Skip to content

Commit 6f382e7

Browse files
committed
address code smells - part 1
1 parent e443f13 commit 6f382e7

File tree

17 files changed

+180
-72
lines changed

17 files changed

+180
-72
lines changed

api/src/main/java/com/cloud/network/Network.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ public static class Provider {
205205
//Add Tungsten Fabric provider
206206
public static final Provider Tungsten = new Provider("Tungsten", false);
207207

208-
//TODO: should it be true?
209208
public static final Provider Nsx = new Provider("Nsx", false);
210209

211210
private final String name;

api/src/main/java/com/cloud/network/Networks.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ public <T> URI toUri(T value) {
343343
}
344344
},
345345
Vswitch("vs", String.class), Undecided(null, null), Vnet("vnet", Long.class);
346-
// NSX("nsx", String.class);
347346

348347
private final String scheme;
349348
private final Class<?> type;

api/src/main/java/com/cloud/network/vpc/VpcOffering.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public enum State {
2929
public static final String defaultVPCOfferingName = "Default VPC offering";
3030
public static final String defaultVPCNSOfferingName = "Default VPC offering with Netscaler";
3131
public static final String redundantVPCOfferingName = "Redundant VPC offering";
32-
public static final String defaultVPCNSXSOfferingName = "VPC offering with NSX";
32+
public static final String DEFAULT_VPC_NSX_OFFERING_NAME = "VPC offering with NSX";
3333

3434
/**
3535
*

engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.persistence.GenerationType;
2626
import javax.persistence.Id;
2727
import javax.persistence.Table;
28+
import java.util.List;
2829
import java.util.UUID;
2930

3031
@Entity
@@ -71,18 +72,6 @@ public NsxProviderVO() {
7172
this.uuid = UUID.randomUUID().toString();
7273
}
7374

74-
public NsxProviderVO( long zoneId, long hostId, String providerName, String hostname, String username, String password, String tier0Gateway, String edgeCluster) {
75-
this.zoneId = zoneId;
76-
this.hostId = hostId;
77-
this.uuid = UUID.randomUUID().toString();
78-
this.providerName = providerName;
79-
this.hostname = hostname;
80-
this.username = username;
81-
this.password = password;
82-
this.tier0Gateway = tier0Gateway;
83-
this.edgeCluster = edgeCluster;
84-
}
85-
8675
@Override
8776
public long getId() {
8877
return id;
@@ -177,4 +166,78 @@ public String getEdgeCluster() {
177166
public void setEdgeCluster(String edgeCluster) {
178167
this.edgeCluster = edgeCluster;
179168
}
169+
170+
public static final class Builder {
171+
private long zoneId;
172+
private long hostId;
173+
private String providerName;
174+
private String hostname;
175+
private String port;
176+
private String username;
177+
private String password;
178+
private String tier0Gateway;
179+
private String edgeCluster;
180+
181+
public Builder() {
182+
}
183+
184+
public Builder setZoneId(long zoneId) {
185+
this.zoneId = zoneId;
186+
return this;
187+
}
188+
189+
public Builder setHostId(long hostId) {
190+
this.hostId = hostId;
191+
return this;
192+
}
193+
194+
public Builder setProviderName(String providerName) {
195+
this.providerName = providerName;
196+
return this;
197+
}
198+
199+
public Builder setHostname(String hostname) {
200+
this.hostname = hostname;
201+
return this;
202+
}
203+
204+
public Builder setPort(String port) {
205+
this.port = port;
206+
return this;
207+
}
208+
209+
public Builder setUsername(String username) {
210+
this.username = username;
211+
return this;
212+
}
213+
214+
public Builder setPassword(String password) {
215+
this.password = password;
216+
return this;
217+
}
218+
219+
public Builder setTier0Gateway(String tier0Gateway) {
220+
this.tier0Gateway = tier0Gateway;
221+
return this;
222+
}
223+
224+
public Builder setEdgeCluster(String edgeCluster) {
225+
this.edgeCluster = edgeCluster;
226+
return this;
227+
}
228+
public NsxProviderVO build() {
229+
NsxProviderVO provider = new NsxProviderVO();
230+
provider.setZoneId(this.zoneId);
231+
provider.setHostId(this.hostId);
232+
provider.setUuid(UUID.randomUUID().toString());
233+
provider.setProviderName(this.providerName);
234+
provider.setHostname(this.hostname);
235+
provider.setPort(this.port);
236+
provider.setUsername(this.username);
237+
provider.setPassword(this.password);
238+
provider.setTier0Gateway(this.tier0Gateway);
239+
provider.setEdgeCluster(this.edgeCluster);
240+
return provider;
241+
}
242+
}
180243
}

engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ CREATE TABLE `cloud`.`nsx_providers` (
193193
`password` varchar(255) NOT NULL,
194194
`tier0_gateway` varchar(255),
195195
`edge_cluster` varchar(255),
196+
`created` datetime NOT NULL COMMENT 'date created',
197+
`removed` datetime COMMENT 'date removed if not null',
196198
PRIMARY KEY (`id`),
197199
CONSTRAINT `fk_nsx_providers__zone_id` FOREIGN KEY `fk_nsx_providers__zone_id` (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE,
198200
INDEX `i_nsx_providers__zone_id`(`zone_id`)

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxSegmentCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.cloud.network.dao.NetworkVO;
2020

21+
import java.util.Objects;
22+
2123
public class CreateNsxSegmentCommand extends CreateNsxTier1GatewayCommand {
2224
private NetworkVO tierNetwork;
2325
public CreateNsxSegmentCommand(String zoneName, Long zoneId, String accountName, Long accountId, String vpcName, NetworkVO tierNetwork) {
@@ -32,4 +34,18 @@ public NetworkVO getTierNetwork() {
3234
public void setTierNetwork(NetworkVO tierNetwork) {
3335
this.tierNetwork = tierNetwork;
3436
}
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
if (this == o) return true;
41+
if (o == null || getClass() != o.getClass()) return false;
42+
if (!super.equals(o)) return false;
43+
CreateNsxSegmentCommand command = (CreateNsxSegmentCommand) o;
44+
return Objects.equals(tierNetwork, command.tierNetwork);
45+
}
46+
47+
@Override
48+
public int hashCode() {
49+
return Objects.hash(super.hashCode(), tierNetwork);
50+
}
3551
}

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxTier1GatewayCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.agent.api;
1818

19+
import java.util.Objects;
20+
1921
public class CreateNsxTier1GatewayCommand extends NsxCommand {
2022
private String vpcName;
2123

@@ -31,4 +33,18 @@ public String getVpcName() {
3133
public void setVpcName(String vpcName) {
3234
this.vpcName = vpcName;
3335
}
36+
37+
@Override
38+
public boolean equals(Object o) {
39+
if (this == o) return true;
40+
if (o == null || getClass() != o.getClass()) return false;
41+
if (!super.equals(o)) return false;
42+
CreateNsxTier1GatewayCommand that = (CreateNsxTier1GatewayCommand) o;
43+
return Objects.equals(vpcName, that.vpcName);
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return Objects.hash(super.hashCode(), vpcName);
49+
}
3450
}

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.cloud.agent.api.Command;
2020

21+
import java.util.Objects;
22+
2123
public class NsxCommand extends Command {
2224
private String zoneName;
2325
private Long zoneId;
@@ -66,4 +68,18 @@ public void setAccountId(Long accountId) {
6668
public boolean executeInSequence() {
6769
return false;
6870
}
71+
72+
@Override
73+
public boolean equals(Object o) {
74+
if (this == o) return true;
75+
if (o == null || getClass() != o.getClass()) return false;
76+
if (!super.equals(o)) return false;
77+
NsxCommand that = (NsxCommand) o;
78+
return Objects.equals(zoneName, that.zoneName) && Objects.equals(zoneId, that.zoneId) && Objects.equals(accountName, that.accountName) && Objects.equals(accountId, that.accountId);
79+
}
80+
81+
@Override
82+
public int hashCode() {
83+
return Objects.hash(super.hashCode(), zoneName, zoneId, accountName, accountId);
84+
}
6985
}

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/AddNsxControllerCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public class AddNsxControllerCmd extends BaseCmd {
5353
@Parameter(name = ApiConstants.NSX_PROVIDER_HOSTNAME, type = CommandType.STRING, required = true, description = "NSX controller hostname / IP address")
5454
private String hostname;
5555

56-
// TODO: May not be required
5756
@Parameter(name = ApiConstants.NSX_PROVIDER_PORT, type = CommandType.STRING, description = "NSX controller port")
5857
private String port;
5958
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Username to log into NSX controller")

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/response/NsxControllerResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public class NsxControllerResponse extends BaseResponse {
4848
@Param(description = "NSX controller port")
4949
private String port;
5050

51-
// TODO: Should Password be returned?
52-
5351
@SerializedName(ApiConstants.TIER0_GATEWAY)
5452
@Param(description = "The tier-0 gateway network. Tier-0 gateway is responsible for handling" +
5553
" traffic between logical and physical networks"

0 commit comments

Comments
 (0)