Skip to content

Commit 97ddd8d

Browse files
malcolmtaylorGabrielBrascher
authored andcommitted
Fix some LGTM alerts (apache#3143)
* Fix some LGTM alerts * address review comments from Gabriel Brascher and Rafael Weingartner
1 parent c496c84 commit 97ddd8d

File tree

6 files changed

+20
-67
lines changed

6 files changed

+20
-67
lines changed

api/src/main/java/com/cloud/deploy/DeployDestination.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,35 @@ public int hashCode() {
7878

7979
@Override
8080
public boolean equals(Object obj) {
81+
if (obj == null) {
82+
return false;
83+
}
84+
if (!(obj instanceof DeployDestination)) {
85+
return false;
86+
}
8187
DeployDestination that = (DeployDestination)obj;
82-
if (_dc == null || that._dc == null) {
88+
if (this._dc == null || that._dc == null) {
8389
return false;
8490
}
85-
if (_dc.getId() != that._dc.getId()) {
91+
if (this._dc.getId() != that._dc.getId()) {
8692
return false;
8793
}
88-
if (_pod == null || that._pod == null) {
94+
if (this._pod == null || that._pod == null) {
8995
return false;
9096
}
91-
if (_pod.getId() != that._pod.getId()) {
97+
if (this._pod.getId() != that._pod.getId()) {
9298
return false;
9399
}
94-
if (_cluster == null || that._cluster == null) {
100+
if (this._cluster == null || that._cluster == null) {
95101
return false;
96102
}
97-
if (_cluster.getId() != that._cluster.getId()) {
103+
if (this._cluster.getId() != that._cluster.getId()) {
98104
return false;
99105
}
100-
if (_host == null || that._host == null) {
106+
if (this._host == null || that._host == null) {
101107
return false;
102108
}
103-
return _host.getId() == that._host.getId();
109+
return this._host.getId() == that._host.getId();
104110
}
105111

106112
@Override

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) throws
780780
}
781781

782782
final int devId = vmNic.getDeviceId();
783-
if (devId > deviceIds.length) {
783+
if (devId >= deviceIds.length) {
784784
throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
785785
}
786786
if (deviceIds[devId]) {

plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java

-40
Original file line numberDiff line numberDiff line change
@@ -439,50 +439,10 @@ public final Answer executeRequest(final Command cmd) {
439439
return _vrResource.executeRequest((NetworkElementCommand)cmd);
440440
}if (clazz == CheckSshCommand.class) {
441441
answer = execute((CheckSshCommand)cmd);
442-
} else if (clazz == GetDomRVersionCmd.class) {
443-
answer = execute((GetDomRVersionCmd)cmd);
444442
} else if (cmd instanceof NetworkUsageCommand) {
445443
answer = execute((NetworkUsageCommand)cmd);
446-
} else if (clazz == IpAssocCommand.class) {
447-
answer = execute((IpAssocCommand)cmd);
448-
} else if (clazz == DnsMasqConfigCommand.class) {
449-
return execute((DnsMasqConfigCommand)cmd);
450-
} else if (clazz == CreateIpAliasCommand.class) {
451-
return execute((CreateIpAliasCommand)cmd);
452-
} else if (clazz == DhcpEntryCommand.class) {
453-
answer = execute((DhcpEntryCommand)cmd);
454-
} else if (clazz == VmDataCommand.class) {
455-
answer = execute((VmDataCommand)cmd);
456-
} else if (clazz == SavePasswordCommand.class) {
457-
answer = execute((SavePasswordCommand)cmd);
458-
} else if (clazz == SetFirewallRulesCommand.class) {
459-
answer = execute((SetFirewallRulesCommand)cmd);
460-
} else if (clazz == LoadBalancerConfigCommand.class) {
461-
answer = execute((LoadBalancerConfigCommand)cmd);
462-
} else if (clazz == DeleteIpAliasCommand.class) {
463-
return execute((DeleteIpAliasCommand)cmd);
464444
} else if (clazz == PingTestCommand.class) {
465445
answer = execute((PingTestCommand)cmd);
466-
} else if (clazz == SetStaticNatRulesCommand.class) {
467-
answer = execute((SetStaticNatRulesCommand)cmd);
468-
} else if (clazz == CheckRouterCommand.class) {
469-
answer = execute((CheckRouterCommand)cmd);
470-
} else if (clazz == SetPortForwardingRulesCommand.class) {
471-
answer = execute((SetPortForwardingRulesCommand)cmd);
472-
} else if (clazz == SetSourceNatCommand.class) {
473-
answer = execute((SetSourceNatCommand)cmd);
474-
} else if (clazz == Site2SiteVpnCfgCommand.class) {
475-
answer = execute((Site2SiteVpnCfgCommand)cmd);
476-
} else if (clazz == CheckS2SVpnConnectionsCommand.class) {
477-
answer = execute((CheckS2SVpnConnectionsCommand) cmd);
478-
} else if (clazz == RemoteAccessVpnCfgCommand.class) {
479-
answer = execute((RemoteAccessVpnCfgCommand) cmd);
480-
} else if (clazz == VpnUsersCfgCommand.class) {
481-
answer = execute((VpnUsersCfgCommand) cmd);
482-
} else if (clazz == SetStaticRouteCommand.class) {
483-
answer = execute((SetStaticRouteCommand) cmd);
484-
} else if (clazz == SetMonitorServiceCommand.class) {
485-
answer = execute((SetMonitorServiceCommand) cmd);
486446
} else if (clazz == PlugNicCommand.class) {
487447
answer = execute((PlugNicCommand)cmd);
488448
} else if (clazz == UnPlugNicCommand.class) {

plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java

-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.apache.cloudstack.storage.command.AttachCommand;
2828
import org.apache.cloudstack.storage.command.CopyCommand;
2929
import org.apache.cloudstack.storage.command.CreateObjectCommand;
30-
import org.apache.cloudstack.storage.command.DeleteCommand;
31-
import org.apache.cloudstack.storage.command.DettachCommand;
3230
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
3331
import org.apache.log4j.Logger;
3432

@@ -195,18 +193,12 @@ public Answer executeRequest(Command cmd) {
195193
return storageprocessor.execute((CopyCommand)cmd);
196194
} else if (cmd instanceof StorageSubSystemCommand) {
197195
return storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
198-
} else if (clazz == DeleteCommand.class) {
199-
return storageprocessor.execute((DeleteCommand)cmd);
200196
} else if (clazz == CreateCommand.class) {
201197
return storageprocessor.execute((CreateCommand)cmd);
202198
} else if (clazz == CreateObjectCommand.class) {
203199
return storageprocessor.execute((CreateObjectCommand)cmd);
204200
} else if (clazz == AttachIsoCommand.class) {
205201
return storageprocessor.attachIso((AttachCommand)cmd);
206-
} else if (clazz == DettachCommand.class) {
207-
return storageprocessor.execute((DettachCommand)cmd);
208-
} else if (clazz == AttachCommand.class) {
209-
return storageprocessor.execute((AttachCommand)cmd);
210202
} else if (clazz == CreatePrivateTemplateFromVolumeCommand.class) {
211203
return storageprocessor.execute((CreatePrivateTemplateFromVolumeCommand)cmd);
212204
} else if (clazz == DestroyCommand.class) {

server/src/main/java/com/cloud/api/ApiResponseHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public PodResponse createPodResponse(Pod pod, Boolean showCapacities) {
980980
endIp.add(((existingPodIpRange.length > 1) && (existingPodIpRange[1] != null)) ? existingPodIpRange[1] : "");
981981
forSystemVms.add((existingPodIpRange.length > 2) && (existingPodIpRange[2] != null) ? existingPodIpRange[2] : "0");
982982
vlanIds.add((existingPodIpRange.length > 3) &&
983-
(existingPodIpRange[3] != null && !existingPodIpRange.equals("untagged")) ?
983+
(existingPodIpRange[3] != null && !existingPodIpRange[3].equals("untagged")) ?
984984
BroadcastDomainType.Vlan.toUri(existingPodIpRange[3]).toString() :
985985
BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString());
986986
}

server/src/main/java/com/cloud/api/ApiServer.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@
7474
import org.apache.cloudstack.api.ResponseObject.ResponseView;
7575
import org.apache.cloudstack.api.ServerApiException;
7676
import org.apache.cloudstack.api.auth.APIAuthenticationManager;
77-
import org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin;
7877
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
7978
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
8079
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
8180
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
82-
import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
83-
import org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin;
84-
import org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin;
8581
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
8682
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
8783
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
@@ -732,14 +728,13 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
732728
// if the command is of the listXXXCommand, we will need to also return the
733729
// the job id and status if possible
734730
// For those listXXXCommand which we have already created DB views, this step is not needed since async job is joined in their db views.
735-
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListVMsCmdByAdmin) && !(cmdObj instanceof ListRoutersCmd)
731+
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd)
736732
&& !(cmdObj instanceof ListSecurityGroupsCmd) &&
737733
!(cmdObj instanceof ListTagsCmd) && !(cmdObj instanceof ListEventsCmd) && !(cmdObj instanceof ListVMGroupsCmd) && !(cmdObj instanceof ListProjectsCmd) &&
738734
!(cmdObj instanceof ListProjectAccountsCmd) && !(cmdObj instanceof ListProjectInvitationsCmd) && !(cmdObj instanceof ListHostsCmd) &&
739-
!(cmdObj instanceof ListVolumesCmd) && !(cmdObj instanceof ListVolumesCmdByAdmin) && !(cmdObj instanceof ListUsersCmd) && !(cmdObj instanceof ListAccountsCmd)
740-
&& !(cmdObj instanceof ListAccountsCmdByAdmin) &&
741-
!(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) &&
742-
!(cmdObj instanceof ListZonesCmd) && !(cmdObj instanceof ListZonesCmdByAdmin)) {
735+
!(cmdObj instanceof ListVolumesCmd) && !(cmdObj instanceof ListUsersCmd) && !(cmdObj instanceof ListAccountsCmd)
736+
&& !(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) &&
737+
!(cmdObj instanceof ListZonesCmd)) {
743738
buildAsyncListResponse((BaseListCmd)cmdObj, caller);
744739
}
745740

0 commit comments

Comments
 (0)