View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.jclouds.cloudloadbalancers.functions;
20  
21  import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
22  import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Builder;
23  
24  import com.google.common.base.Function;
25  import com.google.common.collect.Iterables;
26  
27  /**
28   * @author Adrian Cole
29   */
30  public class ConvertLB implements Function<LB, LoadBalancer> {
31  
32     private final String region;
33  
34     ConvertLB(String region) {
35        this.region = region.toUpperCase();
36     }
37  
38     @Override
39     public LoadBalancer apply(LB lb) {
40        Builder builder = LoadBalancer.builder().region(region).name(lb.getName()).port(lb.getPort()).protocol(
41                 lb.getProtocol()).algorithm(lb.getAlgorithm()).nodes(lb.getNodes()).id(lb.id).status(lb.status)
42                 .virtualIPs(lb.virtualIps);
43        if (lb.cluster.size() == 1)
44           builder.clusterName(Iterables.get(lb.cluster.values(), 0));
45        if (lb.sessionPersistence.size() == 1)
46           builder.sessionPersistenceType(Iterables.get(lb.sessionPersistence.values(), 0));
47        if (lb.created.size() == 1)
48           builder.created(Iterables.get(lb.created.values(), 0));
49        if (lb.updated.size() == 1)
50           builder.updated(Iterables.get(lb.updated.values(), 0));
51        if (lb.connectionLogging.size() == 1)
52           builder.connectionLoggingEnabled(Iterables.get(lb.connectionLogging.values(), 0));
53        return builder.build();
54     }
55  
56  }