From 297cb89310db2a2b74810e261543fc4a1173144d Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Wed, 4 Sep 2024 20:52:45 +0200 Subject: [PATCH] api: add since to api and response --- .../network/CreateNetworkCmdByAdmin.java | 2 +- .../admin/vpc/CreateVPCCmdByAdmin.java | 20 ++++++- .../user/network/CreateNetworkCmd.java | 2 +- .../user/network/ListNetworkOfferingsCmd.java | 3 +- .../routing/CreateRoutingFirewallRuleCmd.java | 1 + .../routing/DeleteRoutingFirewallRuleCmd.java | 1 + .../routing/ListRoutingFirewallRulesCmd.java | 1 + .../routing/UpdateRoutingFirewallRuleCmd.java | 5 +- .../api/command/user/vpc/CreateVPCCmd.java | 17 +----- .../api/response/NetworkResponse.java | 4 +- .../cloudstack/api/response/VpcResponse.java | 4 +- .../admin/vpc/CreateVPCCmdByAdminTest.java | 55 +++++++++++++++++++ .../command/user/vpc/CreateVPCCmdTest.java | 9 --- .../com/cloud/network/vpc/VpcManagerImpl.java | 4 +- 14 files changed, 92 insertions(+), 36 deletions(-) create mode 100644 api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java index 74ff2e57d3ab..d8b57f79528c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java @@ -57,7 +57,7 @@ public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCm collectionType = CommandType.UUID, entityType = BgpPeerResponse.class, description = "Ids of the Bgp Peer for the network", - since = "4.20") + since = "4.20.0") private List bgpPeerIds; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java index bd00876ed36c..9dc31f8cefec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java @@ -17,13 +17,31 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; import org.apache.cloudstack.api.response.VpcResponse; import com.cloud.network.vpc.Vpc; +import java.util.List; + @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Full, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) -public class CreateVPCCmdByAdmin extends CreateVPCCmd implements AdminCmd {} +public class CreateVPCCmdByAdmin extends CreateVPCCmd implements AdminCmd { + @Parameter(name = ApiConstants.BGP_PEER_IDS, + type = CommandType.LIST, + collectionType = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "Ids of the Bgp Peer for the VPC", + since = "4.20.0") + private List bgpPeerIds; + + + public List getBgpPeerIds() { + return bgpPeerIds; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java index 23ed891966e1..aca3d3ca1b45 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java @@ -193,7 +193,7 @@ public class CreateNetworkCmd extends BaseCmd implements UserCmd { @Parameter(name = ApiConstants.CIDR_SIZE, type = CommandType.INTEGER, description = "the CIDR size of IPv4 network. For regular users, this is required for isolated networks with ROUTED mode.", - since = "4.20") + since = "4.20.0") private Integer cidrSize; @Parameter(name=ApiConstants.AS_NUMBER, type=CommandType.LONG, since = "4.20.0", description="the AS Number of the network") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java index 3d455bdafdbc..bdc89d804cdf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java @@ -112,7 +112,8 @@ public class ListNetworkOfferingsCmd extends BaseListCmd { @Parameter(name = ApiConstants.ROUTING_MODE, type = CommandType.STRING, - description = "the routing mode for the network offering. Supported types are: Static or Dynamic.") + description = "the routing mode for the network offering. Supported types are: Static or Dynamic.", + since = "4.20.0") private String routingMode; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java index b7142840e6d3..7146d1ae1d19 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java @@ -44,6 +44,7 @@ @APICommand(name = "createRoutingFirewallRule", description = "Creates a routing firewall rule in the given network in ROUTED mode", + since = "4.20.0", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java index 4921901f3eb6..16696f5f71b7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java @@ -35,6 +35,7 @@ @APICommand(name = "deleteRoutingFirewallRule", description = "Deletes a routing firewall rule", + since = "4.20.0", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java index 15042ee5509a..3fdf3b0f5b46 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java @@ -35,6 +35,7 @@ @APICommand(name = "listRoutingFirewallRules", description = "Lists all Routing firewall rules", + since = "4.20.0", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java index 718f821c05c2..c6f6034b1ba1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java @@ -33,6 +33,7 @@ @APICommand(name = "updateRoutingFirewallRule", description = "Updates Routing firewall rule with specified ID", + since = "4.20.0", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, @@ -47,8 +48,8 @@ public class UpdateRoutingFirewallRuleCmd extends BaseAsyncCustomIdCmd { @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Routing firewall rule") private Long id; - @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the Routing firewall rule to the end user or not", since = "4.4", authorized = { - RoleType.Admin}) + @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the Routing firewall rule to the end user or not", + authorized = {RoleType.Admin}) private Boolean display; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 56942846edc3..2f62d0d7210d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.cloudstack.api.response.BgpPeerResponse; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.acl.RoleType; @@ -43,8 +42,6 @@ import com.cloud.network.NetworkService; import com.cloud.network.vpc.Vpc; -import java.util.List; - @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { @@ -84,7 +81,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { @Parameter(name = ApiConstants.CIDR_SIZE, type = CommandType.INTEGER, description = "the CIDR size of VPC. For regular users, this is required for VPC with ROUTED mode.", - since = "4.20") + since = "4.20.0") private Integer cidrSize; @Parameter(name = ApiConstants.VPC_OFF_ID, type = CommandType.UUID, entityType = VpcOfferingResponse.class, @@ -128,14 +125,6 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { @Parameter(name=ApiConstants.AS_NUMBER, type=CommandType.LONG, since = "4.20.0", description="the AS Number of the VPC tiers") private Long asNumber; - @Parameter(name = ApiConstants.BGP_PEER_IDS, - type = CommandType.LIST, - collectionType = CommandType.UUID, - entityType = BgpPeerResponse.class, - description = "Ids of the Bgp Peer for the VPC", - since = "4.20") - private List bgpPeerIds; - // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// // /////////////////////////////////////////////////// @@ -216,10 +205,6 @@ public Long getAsNumber() { return asNumber; } - public List getBgpPeerIds() { - return bgpPeerIds; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java index d7c67ed9d14a..a80317c83cd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java @@ -137,11 +137,11 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement private String vlan; @SerializedName(ApiConstants.AS_NUMBER_ID) - @Param(description = "UUID of AS NUMBER") + @Param(description = "UUID of AS NUMBER", since = "4.20.0") private String asNumberId; @SerializedName(ApiConstants.AS_NUMBER) - @Param(description = "AS NUMBER") + @Param(description = "AS NUMBER", since = "4.20.0") private Long asNumber; @SerializedName(ApiConstants.ACL_TYPE) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java index 6918bf702d4c..56479506686a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java @@ -170,11 +170,11 @@ public class VpcResponse extends BaseResponseWithAnnotations implements Controll private Set ipv4Routes; @SerializedName(ApiConstants.AS_NUMBER_ID) - @Param(description = "UUID of AS NUMBER") + @Param(description = "UUID of AS NUMBER", since = "4.20.0") private String asNumberId; @SerializedName(ApiConstants.AS_NUMBER) - @Param(description = "AS NUMBER") + @Param(description = "AS NUMBER", since = "4.20.0") private Long asNumber; @SerializedName(ApiConstants.BGP_PEERS) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java new file mode 100644 index 000000000000..c4e21bb948b2 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.vpc; + +import com.cloud.network.vpc.VpcService; +import com.cloud.user.AccountService; +import com.cloud.utils.db.EntityManager; +import junit.framework.TestCase; +import org.apache.cloudstack.api.ResponseGenerator; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class CreateVPCCmdByAdminTest extends TestCase { + + @Mock + public VpcService _vpcService; + @Mock + public EntityManager _entityMgr; + @Mock + public AccountService _accountService; + private ResponseGenerator responseGenerator; + @InjectMocks + CreateVPCCmdByAdmin cmd = new CreateVPCCmdByAdmin(); + + @Test + public void testBgpPeerIds() { + List bgpPeerIds = Mockito.mock(List.class); + ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); + Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java index 54a3434381b6..2505c67e87db 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java @@ -38,8 +38,6 @@ import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; -import java.util.List; - @RunWith(MockitoJUnitRunner.class) public class CreateVPCCmdTest extends TestCase { @@ -102,13 +100,6 @@ public void testAsNumber() { Assert.assertEquals(asNumber, (long) cmd.getAsNumber()); } - @Test - public void testBgpPeerIds() { - List bgpPeerIds = Mockito.mock(List.class); - ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); - Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); - } - @Test public void testGetDisplayText() { String displayText = "VPC Network"; diff --git a/server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java index 5086e7c2c9f5..5198be6aa1d3 100644 --- a/server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java @@ -54,6 +54,7 @@ import org.apache.cloudstack.annotation.dao.AnnotationDao; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.vpc.CreatePrivateGatewayByAdminCmd; +import org.apache.cloudstack.api.command.admin.vpc.CreateVPCCmdByAdmin; import org.apache.cloudstack.api.command.admin.vpc.CreateVPCOfferingCmd; import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd; import org.apache.cloudstack.api.command.user.vpc.CreatePrivateGatewayCmd; @@ -1274,9 +1275,10 @@ private void validateVpcCidrSize(Account caller, long accountId, VpcOffering vpc @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", create = true) public Vpc createVpc(CreateVPCCmd cmd) throws ResourceAllocationException { + List bgpPeerIds = (cmd instanceof CreateVPCCmdByAdmin) ? ((CreateVPCCmdByAdmin)cmd).getBgpPeerIds() : null; Vpc vpc = createVpc(cmd.getZoneId(), cmd.getVpcOffering(), cmd.getEntityOwnerId(), cmd.getVpcName(), cmd.getDisplayText(), cmd.getCidr(), cmd.getNetworkDomain(), cmd.getIp4Dns1(), cmd.getIp4Dns2(), cmd.getIp6Dns1(), - cmd.getIp6Dns2(), cmd.isDisplay(), cmd.getPublicMtu(), cmd.getCidrSize(), cmd.getAsNumber(), cmd.getBgpPeerIds()); + cmd.getIp6Dns2(), cmd.isDisplay(), cmd.getPublicMtu(), cmd.getCidrSize(), cmd.getAsNumber(), bgpPeerIds); String sourceNatIP = cmd.getSourceNatIP(); boolean forNsx = isVpcForNsx(vpc);