Skip to content

Commit

Permalink
api: add since to api and response
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Sep 4, 2024
1 parent 5b73077 commit 297cb89
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> bgpPeerIds;

/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> bgpPeerIds;


public List<Long> getBgpPeerIds() {
return bgpPeerIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

@APICommand(name = "deleteRoutingFirewallRule",
description = "Deletes a routing firewall rule",
since = "4.20.0",
responseObject = SuccessResponse.class,
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

@APICommand(name = "listRoutingFirewallRules",
description = "Lists all Routing firewall rules",
since = "4.20.0",
responseObject = FirewallRuleResponse.class,
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

// ///////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Long> bgpPeerIds;

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
Expand Down Expand Up @@ -216,10 +205,6 @@ public Long getAsNumber() {
return asNumber;
}

public List<Long> getBgpPeerIds() {
return bgpPeerIds;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public class VpcResponse extends BaseResponseWithAnnotations implements Controll
private Set<Ipv4RouteResponse> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Long> bgpPeerIds = Mockito.mock(List.class);
ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds);
Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -102,13 +100,6 @@ public void testAsNumber() {
Assert.assertEquals(asNumber, (long) cmd.getAsNumber());
}

@Test
public void testBgpPeerIds() {
List<Long> bgpPeerIds = Mockito.mock(List.class);
ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds);
Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds());
}

@Test
public void testGetDisplayText() {
String displayText = "VPC Network";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Long> 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);
Expand Down

0 comments on commit 297cb89

Please sign in to comment.