Skip to content

Commit d378130

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

File tree

17 files changed

+179
-72
lines changed

17 files changed

+179
-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: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ public NsxProviderVO() {
7171
this.uuid = UUID.randomUUID().toString();
7272
}
7373

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-
8674
@Override
8775
public long getId() {
8876
return id;
@@ -177,4 +165,78 @@ public String getEdgeCluster() {
177165
public void setEdgeCluster(String edgeCluster) {
178166
this.edgeCluster = edgeCluster;
179167
}
168+
169+
public static final class Builder {
170+
private long zoneId;
171+
private long hostId;
172+
private String providerName;
173+
private String hostname;
174+
private String port;
175+
private String username;
176+
private String password;
177+
private String tier0Gateway;
178+
private String edgeCluster;
179+
180+
public Builder() {
181+
}
182+
183+
public Builder setZoneId(long zoneId) {
184+
this.zoneId = zoneId;
185+
return this;
186+
}
187+
188+
public Builder setHostId(long hostId) {
189+
this.hostId = hostId;
190+
return this;
191+
}
192+
193+
public Builder setProviderName(String providerName) {
194+
this.providerName = providerName;
195+
return this;
196+
}
197+
198+
public Builder setHostname(String hostname) {
199+
this.hostname = hostname;
200+
return this;
201+
}
202+
203+
public Builder setPort(String port) {
204+
this.port = port;
205+
return this;
206+
}
207+
208+
public Builder setUsername(String username) {
209+
this.username = username;
210+
return this;
211+
}
212+
213+
public Builder setPassword(String password) {
214+
this.password = password;
215+
return this;
216+
}
217+
218+
public Builder setTier0Gateway(String tier0Gateway) {
219+
this.tier0Gateway = tier0Gateway;
220+
return this;
221+
}
222+
223+
public Builder setEdgeCluster(String edgeCluster) {
224+
this.edgeCluster = edgeCluster;
225+
return this;
226+
}
227+
public NsxProviderVO build() {
228+
NsxProviderVO provider = new NsxProviderVO();
229+
provider.setZoneId(this.zoneId);
230+
provider.setHostId(this.hostId);
231+
provider.setUuid(UUID.randomUUID().toString());
232+
provider.setProviderName(this.providerName);
233+
provider.setHostname(this.hostname);
234+
provider.setPort(this.port);
235+
provider.setUsername(this.username);
236+
provider.setPassword(this.password);
237+
provider.setTier0Gateway(this.tier0Gateway);
238+
provider.setEdgeCluster(this.edgeCluster);
239+
return provider;
240+
}
241+
}
180242
}

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)