Skip to content

Commit 326b371

Browse files
formatting to make checkstyle happy
1 parent 876c464 commit 326b371

5 files changed

Lines changed: 49 additions & 58 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public interface NetworkACLService {
120120
* @return
121121
* @throws ResourceUnavailableException
122122
*/
123-
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
124-
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID, Boolean forDisplay) throws ResourceUnavailableException;
123+
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number, Integer sourcePortStart,
124+
Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID, Boolean forDisplay) throws ResourceUnavailableException;
125125

126126
/**
127127
* Associates ACL with specified Network

api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import com.cloud.network.vpc.NetworkACL;
3232
import com.cloud.user.Account;
3333

34-
@APICommand(name = "updateNetworkACLList", description = "Updates network ACL list", responseObject = SuccessResponse.class, since = "4.4",
35-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
34+
@APICommand(name = "updateNetworkACLList", description = "Updates network ACL list", responseObject = SuccessResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3635
public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
3736
public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName());
3837
private static final String s_name = "updatenetworkacllistresponse";
@@ -44,12 +43,13 @@ public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
4443
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = NetworkACLResponse.class, required = true, description = "the ID of the network ACL")
4544
private Long id;
4645

47-
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the list to the end user or not", since = "4.4", authorized = {RoleType.Admin})
46+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the list to the end user or not", since = "4.4", authorized = {
47+
RoleType.Admin})
4848
private Boolean display;
49-
49+
5050
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Name of the network ACL list")
5151
private String name;
52-
52+
5353
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Description of the network ACL list")
5454
private String description;
5555

@@ -103,11 +103,11 @@ public void checkUuid() {
103103
_uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
104104
}
105105
}
106-
106+
107107
public String getDescription() {
108108
return description;
109109
}
110-
110+
111111
public String getName() {
112112
return name;
113113
}

engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ public void setVpcId(long vpcId) {
101101
public boolean isDisplay() {
102102
return display;
103103
}
104-
104+
105105
public void setDescription(String description) {
106106
this.description = description;
107107
}
108+
108109
public void setName(String name) {
109110
this.name = name;
110111
}

server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(final ListNetwo
147147
sc.setParameters("display", display);
148148
}
149149

150-
if(id != null){
150+
if (id != null) {
151151
sc.setParameters("id", id);
152152
}
153153

@@ -174,10 +174,8 @@ public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(final ListNetwo
174174
final String accountName = cmd.getAccountName();
175175
final Long projectId = cmd.getProjectId();
176176
final boolean listAll = cmd.listAll();
177-
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
178-
ListProjectResourcesCriteria>(domainId, isRecursive, null);
179-
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject,
180-
listAll, false);
177+
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
178+
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
181179
domainId = domainIdRecursiveListProject.first();
182180
isRecursive = domainIdRecursiveListProject.second();
183181
final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -200,7 +198,7 @@ public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(final ListNetwo
200198
}
201199

202200
final Filter filter = new Filter(NetworkACLVO.class, "id", false, null, null);
203-
final Pair<List<NetworkACLVO>, Integer> acls = _networkACLDao.searchAndCount(sc, filter);
201+
final Pair<List<NetworkACLVO>, Integer> acls = _networkACLDao.searchAndCount(sc, filter);
204202
return new Pair<List<? extends NetworkACL>, Integer>(acls.first(), acls.second());
205203
}
206204

@@ -262,7 +260,7 @@ public boolean replaceNetworkACLonPrivateGw(final long aclId, final long private
262260
final PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(gateway.getId());
263261
_accountMgr.checkAccess(caller, null, true, privateGateway);
264262

265-
return _networkAclMgr.replaceNetworkACLForPrivateGw(acl, privateGateway);
263+
return _networkAclMgr.replaceNetworkACLForPrivateGw(acl, privateGateway);
266264

267265
}
268266

@@ -377,12 +375,11 @@ public NetworkACLItem createNetworkACLItem(final CreateNetworkACLCmd aclItemCmd)
377375
}
378376
}
379377

380-
validateNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getSourceCidrList(), aclItemCmd.getProtocol(),
381-
aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getAction(), aclItemCmd.getNumber());
378+
validateNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getSourceCidrList(), aclItemCmd.getProtocol(), aclItemCmd.getIcmpCode(),
379+
aclItemCmd.getIcmpType(), aclItemCmd.getAction(), aclItemCmd.getNumber());
382380

383-
return _networkAclMgr.createNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getProtocol(),
384-
aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId, aclItemCmd.getAction(),
385-
aclItemCmd.getNumber(), aclItemCmd.getDisplay());
381+
return _networkAclMgr.createNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getProtocol(), aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(),
382+
aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId, aclItemCmd.getAction(), aclItemCmd.getNumber(), aclItemCmd.getDisplay());
386383
}
387384

388385
private void validateNetworkACLItem(final Integer portStart, final Integer portEnd, final List<String> sourceCidrList, final String protocol, final Integer icmpCode, final Integer icmpType,
@@ -447,8 +444,7 @@ private void validateNetworkACLItem(final Integer portStart, final Integer portE
447444
}
448445
if (icmpCode != null) {
449446
if (icmpCode.longValue() != -1 && !NetUtils.validateIcmpCode(icmpCode.longValue())) {
450-
throw new InvalidParameterValueException("Invalid icmp code; should belong to [0-15] range and can"
451-
+ " be defined when icmpType belongs to [0-40] range");
447+
throw new InvalidParameterValueException("Invalid icmp code; should belong to [0-15] range and can" + " be defined when icmpType belongs to [0-40] range");
452448
}
453449
}
454450
}
@@ -525,7 +521,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
525521
if (networkId != null) {
526522
final Network network = _networkDao.findById(networkId);
527523
aclId = network.getNetworkACLId();
528-
if( aclId == null){
524+
if (aclId == null) {
529525
// No aclId associated with the network.
530526
//Return empty list
531527
return new Pair(new ArrayList<NetworkACLItem>(), 0);
@@ -550,7 +546,6 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
550546
} else {
551547
//ToDo: Add accountId to network_acl_item table for permission check
552548

553-
554549
// aclId is not specified
555550
// List permitted VPCs and filter aclItems
556551
final List<Long> permittedAccounts = new ArrayList<Long>();
@@ -559,10 +554,8 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
559554
final String accountName = cmd.getAccountName();
560555
final Long projectId = cmd.getProjectId();
561556
final boolean listAll = cmd.listAll();
562-
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
563-
ListProjectResourcesCriteria>(domainId, isRecursive, null);
564-
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject,
565-
listAll, false);
557+
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
558+
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
566559
domainId = domainIdRecursiveListProject.first();
567560
isRecursive = domainIdRecursiveListProject.second();
568561
final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -600,7 +593,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
600593

601594
final Pair<List<NetworkACLItemVO>, Integer> result = _networkACLItemDao.searchAndCount(sc, filter);
602595
final List<NetworkACLItemVO> aclItemVOs = result.first();
603-
for (final NetworkACLItemVO item: aclItemVOs) {
596+
for (final NetworkACLItemVO item : aclItemVOs) {
604597
_networkACLItemDao.loadCidrs(item);
605598
}
606599
return new Pair<List<? extends NetworkACLItem>, Integer>(aclItemVOs, result.second());
@@ -610,12 +603,12 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
610603
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_DELETE, eventDescription = "Deleting Network ACL Item", async = true)
611604
public boolean revokeNetworkACLItem(final long ruleId) {
612605
final NetworkACLItemVO aclItem = _networkACLItemDao.findById(ruleId);
613-
if(aclItem != null){
606+
if (aclItem != null) {
614607
final NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId());
615608

616609
final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
617610

618-
if(aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW || aclItem.getAclId() == NetworkACL.DEFAULT_DENY){
611+
if (aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW || aclItem.getAclId() == NetworkACL.DEFAULT_DENY) {
619612
throw new InvalidParameterValueException("ACL Items in default ACL cannot be deleted");
620613
}
621614

@@ -629,7 +622,8 @@ public boolean revokeNetworkACLItem(final long ruleId) {
629622

630623
@Override
631624
public NetworkACLItem updateNetworkACLItem(final Long id, final String protocol, final List<String> sourceCidrList, final NetworkACLItem.TrafficType trafficType, final String action,
632-
final Integer number, final Integer sourcePortStart, final Integer sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String newUUID, final Boolean forDisplay) throws ResourceUnavailableException {
625+
final Integer number, final Integer sourcePortStart, final Integer sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String newUUID, final Boolean forDisplay)
626+
throws ResourceUnavailableException {
633627
final NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
634628
if (aclItem == null) {
635629
throw new InvalidParameterValueException("Unable to find ACL Item cannot be found");
@@ -655,8 +649,8 @@ public NetworkACLItem updateNetworkACLItem(final Long id, final String protocol,
655649
}
656650
}
657651

658-
validateNetworkACLItem(sourcePortStart == null ? aclItem.getSourcePortStart() : sourcePortStart, sourcePortEnd == null ? aclItem.getSourcePortEnd()
659-
: sourcePortEnd, sourceCidrList, protocol, icmpCode, icmpType == null ? aclItem.getIcmpType() : icmpType, action, number);
652+
validateNetworkACLItem(sourcePortStart == null ? aclItem.getSourcePortStart() : sourcePortStart, sourcePortEnd == null ? aclItem.getSourcePortEnd() : sourcePortEnd, sourceCidrList, protocol,
653+
icmpCode, icmpType == null ? aclItem.getIcmpType() : icmpType, action, number);
660654

661655
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID, forDisplay);
662656
}
@@ -688,6 +682,6 @@ public NetworkACL updateNetworkACL(UpdateNetworkACLListCmd updateNetworkACLListC
688682
}
689683
_networkACLDao.update(id, acl);
690684
return _networkACLDao.findById(id);
691-
}
685+
}
692686

693687
}

server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
44
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
55
import org.apache.cloudstack.context.CallContext;
6-
import org.apache.commons.lang.StringUtils;
76
import org.junit.Before;
87
import org.junit.Test;
98
import org.junit.runner.RunWith;
@@ -12,7 +11,6 @@
1211
import org.mockito.Mock;
1312
import org.mockito.Mockito;
1413
import org.mockito.Spy;
15-
import org.mockito.runners.MockitoJUnitRunner;
1614
import org.powermock.api.mockito.PowerMockito;
1715
import org.powermock.core.classloader.annotations.PrepareForTest;
1816
import org.powermock.modules.junit4.PowerMockRunner;
@@ -34,22 +32,22 @@ public class NetworkACLServiceImplTest {
3432
private AccountManager accountManager;
3533
@Mock
3634
private EntityManager entityManager;
37-
35+
3836
@Mock
39-
private UpdateNetworkACLListCmd updateNetworkACLListCmdMock;
37+
private UpdateNetworkACLListCmd updateNetworkACLListCmdMock;
4038
@Mock
4139
private NetworkACLVO networkACLVOMock;
42-
40+
4341
private long networkAclListId = 1l;
44-
42+
4543
@Before
4644
public void before() {
4745
Mockito.when(networkACLDao.findById(networkAclListId)).thenReturn(networkACLVOMock);
48-
46+
4947
PowerMockito.mockStatic(CallContext.class);
5048
PowerMockito.when(CallContext.current()).thenReturn(Mockito.mock(CallContext.class));
5149
}
52-
50+
5351
@Test
5452
@PrepareForTest(CallContext.class)
5553
public void updateNetworkACLTestParametersNotNull() {
@@ -62,25 +60,24 @@ public void updateNetworkACLTestParametersNotNull() {
6260
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(customId);
6361
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
6462
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(false);
65-
63+
6664
networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
67-
65+
6866
InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager, entityManager, accountManager, networkACLVOMock);
69-
67+
7068
inOrder.verify(networkACLDao).findById(networkAclListId);
7169
inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class), Mockito.anyLong());
7270
inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class), Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
73-
71+
7472
inOrder.verify(networkACLVOMock).setName(name);
7573
inOrder.verify(networkACLVOMock).setDescription(description);
7674
inOrder.verify(networkACLVOMock).setUuid(customId);
7775
inOrder.verify(networkACLVOMock).setDisplay(false);
78-
76+
7977
inOrder.verify(networkACLDao).update(networkAclListId, networkACLVOMock);
8078
inOrder.verify(networkACLDao).findById(networkAclListId);
8179
}
82-
83-
80+
8481
@Test
8582
@PrepareForTest(CallContext.class)
8683
public void updateNetworkACLTestParametersWithNullValues() {
@@ -89,22 +86,21 @@ public void updateNetworkACLTestParametersWithNullValues() {
8986
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(null);
9087
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
9188
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(null);
92-
89+
9390
networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
94-
91+
9592
InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager, entityManager, accountManager, networkACLVOMock);
96-
93+
9794
inOrder.verify(networkACLDao).findById(networkAclListId);
9895
inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class), Mockito.anyLong());
9996
inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class), Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
100-
97+
10198
Mockito.verify(networkACLVOMock, Mockito.times(0)).setName(null);
10299
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDescription(null);
103100
inOrder.verify(networkACLVOMock, Mockito.times(0)).setUuid(null);
104101
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDisplay(false);
105-
102+
106103
inOrder.verify(networkACLDao).update(networkAclListId, networkACLVOMock);
107104
inOrder.verify(networkACLDao).findById(networkAclListId);
108105
}
109106
}
110-

0 commit comments

Comments
 (0)