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.compute.domain; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.net.URI; |
24 | import java.util.Map; |
25 | import java.util.Set; |
26 | |
27 | import org.jclouds.javax.annotation.Nullable; |
28 | |
29 | import org.jclouds.compute.domain.internal.NodeMetadataImpl; |
30 | import org.jclouds.domain.Credentials; |
31 | import org.jclouds.domain.Location; |
32 | |
33 | import com.google.common.collect.ImmutableSet; |
34 | import com.google.common.collect.Sets; |
35 | |
36 | /** |
37 | * @author Adrian Cole |
38 | */ |
39 | public class NodeMetadataBuilder extends ComputeMetadataBuilder { |
40 | private NodeState state; |
41 | private Set<String> publicAddresses = Sets.newLinkedHashSet(); |
42 | private Set<String> privateAddresses = Sets.newLinkedHashSet(); |
43 | @Nullable |
44 | private String adminPassword; |
45 | @Nullable |
46 | private Credentials credentials; |
47 | @Nullable |
48 | private String group; |
49 | private int loginPort = 22; |
50 | @Nullable |
51 | private String imageId; |
52 | @Nullable |
53 | private Hardware hardware; |
54 | @Nullable |
55 | private OperatingSystem os; |
56 | @Nullable |
57 | private String hostname; |
58 | |
59 | public NodeMetadataBuilder() { |
60 | super(ComputeType.NODE); |
61 | } |
62 | |
63 | public NodeMetadataBuilder loginPort(int loginPort) { |
64 | this.loginPort = loginPort; |
65 | return this; |
66 | } |
67 | |
68 | public NodeMetadataBuilder state(NodeState state) { |
69 | this.state = checkNotNull(state, "state"); |
70 | return this; |
71 | } |
72 | |
73 | public NodeMetadataBuilder publicAddresses(Iterable<String> publicAddresses) { |
74 | this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); |
75 | return this; |
76 | } |
77 | |
78 | public NodeMetadataBuilder privateAddresses(Iterable<String> privateAddresses) { |
79 | this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); |
80 | return this; |
81 | } |
82 | |
83 | public NodeMetadataBuilder credentials(@Nullable Credentials credentials) { |
84 | this.credentials = credentials; |
85 | return this; |
86 | } |
87 | |
88 | public NodeMetadataBuilder adminPassword(@Nullable String adminPassword) { |
89 | this.adminPassword = adminPassword; |
90 | return this; |
91 | } |
92 | |
93 | public NodeMetadataBuilder group(@Nullable String group) { |
94 | this.group = group; |
95 | return this; |
96 | } |
97 | |
98 | public NodeMetadataBuilder imageId(@Nullable String imageId) { |
99 | this.imageId = imageId; |
100 | return this; |
101 | } |
102 | |
103 | public NodeMetadataBuilder hardware(@Nullable Hardware hardware) { |
104 | this.hardware = hardware; |
105 | return this; |
106 | } |
107 | |
108 | public NodeMetadataBuilder operatingSystem(@Nullable OperatingSystem os) { |
109 | this.os = os; |
110 | return this; |
111 | } |
112 | |
113 | public NodeMetadataBuilder hostname(String hostname) { |
114 | this.hostname = hostname; |
115 | return this; |
116 | } |
117 | |
118 | @Override |
119 | public NodeMetadataBuilder id(String id) { |
120 | return NodeMetadataBuilder.class.cast(super.id(id)); |
121 | } |
122 | |
123 | @Override |
124 | public NodeMetadataBuilder tags(Iterable<String> tags) { |
125 | return NodeMetadataBuilder.class.cast(super.tags(tags)); |
126 | } |
127 | |
128 | @Override |
129 | public NodeMetadataBuilder ids(String id) { |
130 | return NodeMetadataBuilder.class.cast(super.ids(id)); |
131 | } |
132 | |
133 | @Override |
134 | public NodeMetadataBuilder providerId(String providerId) { |
135 | return NodeMetadataBuilder.class.cast(super.providerId(providerId)); |
136 | } |
137 | |
138 | @Override |
139 | public NodeMetadataBuilder name(String name) { |
140 | return NodeMetadataBuilder.class.cast(super.name(name)); |
141 | } |
142 | |
143 | @Override |
144 | public NodeMetadataBuilder location(Location location) { |
145 | return NodeMetadataBuilder.class.cast(super.location(location)); |
146 | } |
147 | |
148 | @Override |
149 | public NodeMetadataBuilder uri(URI uri) { |
150 | return NodeMetadataBuilder.class.cast(super.uri(uri)); |
151 | } |
152 | |
153 | @Override |
154 | public NodeMetadataBuilder userMetadata(Map<String, String> userMetadata) { |
155 | return NodeMetadataBuilder.class.cast(super.userMetadata(userMetadata)); |
156 | } |
157 | |
158 | @Override |
159 | public NodeMetadata build() { |
160 | return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tags, group, hardware, imageId, |
161 | os, state, loginPort, publicAddresses, privateAddresses, adminPassword, credentials, hostname); |
162 | } |
163 | |
164 | public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { |
165 | return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( |
166 | node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( |
167 | node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( |
168 | node.getOperatingSystem()).state(node.getState()).loginPort(node.getLoginPort()).publicAddresses( |
169 | node.getPublicAddresses()).privateAddresses(node.getPrivateAddresses()).adminPassword( |
170 | node.getAdminPassword()).credentials(node.getCredentials()).hostname(node.getHostname()); |
171 | } |
172 | |
173 | } |