| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 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 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 | |
| 57 | public NodeMetadataBuilder() { |
| 58 | super(ComputeType.NODE); |
| 59 | } |
| 60 | |
| 61 | public NodeMetadataBuilder loginPort(int loginPort) { |
| 62 | this.loginPort = loginPort; |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | public NodeMetadataBuilder state(NodeState state) { |
| 67 | this.state = checkNotNull(state, "state"); |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | public NodeMetadataBuilder publicAddresses(Iterable<String> publicAddresses) { |
| 72 | this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | public NodeMetadataBuilder privateAddresses(Iterable<String> privateAddresses) { |
| 77 | this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public NodeMetadataBuilder credentials(@Nullable Credentials credentials) { |
| 82 | this.credentials = credentials; |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public NodeMetadataBuilder adminPassword(@Nullable String adminPassword) { |
| 87 | this.adminPassword = adminPassword; |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | public NodeMetadataBuilder group(@Nullable String group) { |
| 92 | this.group = group; |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public NodeMetadataBuilder imageId(@Nullable String imageId) { |
| 97 | this.imageId = imageId; |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | public NodeMetadataBuilder hardware(@Nullable Hardware hardware) { |
| 102 | this.hardware = hardware; |
| 103 | return this; |
| 104 | } |
| 105 | |
| 106 | public NodeMetadataBuilder operatingSystem(@Nullable OperatingSystem os) { |
| 107 | this.os = os; |
| 108 | return this; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public NodeMetadataBuilder id(String id) { |
| 113 | return NodeMetadataBuilder.class.cast(super.id(id)); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public NodeMetadataBuilder ids(String id) { |
| 118 | return NodeMetadataBuilder.class.cast(super.ids(id)); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public NodeMetadataBuilder providerId(String providerId) { |
| 123 | return NodeMetadataBuilder.class.cast(super.providerId(providerId)); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public NodeMetadataBuilder name(String name) { |
| 128 | return NodeMetadataBuilder.class.cast(super.name(name)); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public NodeMetadataBuilder location(Location location) { |
| 133 | return NodeMetadataBuilder.class.cast(super.location(location)); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public NodeMetadataBuilder uri(URI uri) { |
| 138 | return NodeMetadataBuilder.class.cast(super.uri(uri)); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public NodeMetadataBuilder userMetadata(Map<String, String> userMetadata) { |
| 143 | return NodeMetadataBuilder.class.cast(super.userMetadata(userMetadata)); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public NodeMetadata build() { |
| 148 | return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, group, hardware, imageId, os, state, |
| 149 | loginPort, publicAddresses, privateAddresses, adminPassword, credentials); |
| 150 | } |
| 151 | |
| 152 | public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { |
| 153 | return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( |
| 154 | node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).group(node.getGroup()).hardware( |
| 155 | node.getHardware()).imageId(node.getImageId()).operatingSystem(node.getOperatingSystem()).state( |
| 156 | node.getState()).loginPort(node.getLoginPort()).publicAddresses(node.getPublicAddresses()) |
| 157 | .privateAddresses(node.getPrivateAddresses()).adminPassword(node.getAdminPassword()).credentials( |
| 158 | node.getCredentials()); |
| 159 | } |
| 160 | |
| 161 | } |