api_refactor: move usage apis in parts to admin.usage Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0bbe82e8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0bbe82e8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0bbe82e8 Branch: refs/heads/api_refactoring Commit: 0bbe82e8e12c93b69e74414d2d54f0707fe1557c Parents: 52c35bc Author: Rohit Yadav <[email protected]> Authored: Wed Dec 5 14:29:31 2012 -0800 Committer: Rohit Yadav <[email protected]> Committed: Wed Dec 5 14:29:31 2012 -0800 ---------------------------------------------------------------------- .../com/cloud/api/commands/AddTrafficTypeCmd.java | 158 --------------- .../cloud/api/commands/DeleteTrafficTypeCmd.java | 95 --------- .../cloud/api/commands/ListTrafficTypesCmd.java | 88 -------- .../api/admin/usage/command/AddTrafficTypeCmd.java | 158 +++++++++++++++ .../admin/usage/command/DeleteTrafficTypeCmd.java | 95 +++++++++ .../admin/usage/command/ListTrafficTypesCmd.java | 88 ++++++++ client/tomcatconf/commands.properties.in | 6 +- 7 files changed, 344 insertions(+), 344 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/com/cloud/api/commands/AddTrafficTypeCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/AddTrafficTypeCmd.java b/api/src/com/cloud/api/commands/AddTrafficTypeCmd.java deleted file mode 100644 index 9ca682c..0000000 --- a/api/src/com/cloud/api/commands/AddTrafficTypeCmd.java +++ /dev/null @@ -1,158 +0,0 @@ -// 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 com.cloud.api.commands; - -import org.apache.log4j.Logger; - -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseAsyncCreateCmd; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.IdentityMapper; -import org.apache.cloudstack.api.Implementation; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.api.response.TrafficTypeResponse; -import com.cloud.async.AsyncJob; -import com.cloud.event.EventTypes; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.network.PhysicalNetworkTrafficType; -import com.cloud.user.Account; -import com.cloud.user.UserContext; - -@Implementation(description="Adds traffic type to a physical network", responseObject=TrafficTypeResponse.class, since="3.0.0") -public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficTypeCmd.class.getName()); - - private static final String s_name = "addtraffictyperesponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @IdentityMapper(entityTableName="physical_network") - @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") - private Long physicalNetworkId; - - @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the trafficType to be added to the physical network") - private String trafficType; - - @Parameter(name=ApiConstants.XEN_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a XenServer host") - private String xenLabel; - - @Parameter(name=ApiConstants.KVM_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a KVM host") - private String kvmLabel; - - @Parameter(name=ApiConstants.VMWARE_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a VMware host") - private String vmwareLabel; - - @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="The VLAN id to be used for Management traffic by VMware host") - private String vlan; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getEntityTable() { - return "physical_network_traffic_types"; - } - - public Long getPhysicalNetworkId() { - return physicalNetworkId; - } - - public String getTrafficType() { - return trafficType; - } - - public String getXenLabel() { - return xenLabel; - } - - public String getKvmLabel() { - return kvmLabel; - } - - public String getVmwareLabel() { - return vmwareLabel; - } - - public String getSimulatorLabel() { - //simulators will have no labels - return null; - } - - public void setVlan(String vlan) { - this.vlan = vlan; - } - - public String getVlan() { - return vlan; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - UserContext.current().setEventDetails("TrafficType Id: "+getEntityId()); - PhysicalNetworkTrafficType result = _networkService.getPhysicalNetworkTrafficType(getEntityId()); - if (result != null) { - TrafficTypeResponse response = _responseGenerator.createTrafficTypeResponse(result); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); - } - } - - @Override - public void create() throws ResourceAllocationException { - PhysicalNetworkTrafficType result = _networkService.addTrafficTypeToPhysicalNetwork(getPhysicalNetworkId(), getTrafficType(), getXenLabel(), getKvmLabel(), getVmwareLabel(), getSimulatorLabel(), getVlan()); - if (result != null) { - setEntityId(result.getId()); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); - } - } - - @Override - public String getEventType() { - return EventTypes.EVENT_TRAFFIC_TYPE_CREATE; - } - - @Override - public String getEventDescription() { - return "Adding physical network traffic type: " + getEntityId(); - } - - @Override - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.TrafficType; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/com/cloud/api/commands/DeleteTrafficTypeCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/DeleteTrafficTypeCmd.java b/api/src/com/cloud/api/commands/DeleteTrafficTypeCmd.java deleted file mode 100644 index 1a67e84..0000000 --- a/api/src/com/cloud/api/commands/DeleteTrafficTypeCmd.java +++ /dev/null @@ -1,95 +0,0 @@ -// 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 com.cloud.api.commands; - -import org.apache.log4j.Logger; - -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.IdentityMapper; -import org.apache.cloudstack.api.Implementation; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.api.response.SuccessResponse; -import com.cloud.async.AsyncJob; -import com.cloud.event.EventTypes; -import com.cloud.user.Account; - -@Implementation(description="Deletes traffic type of a physical network", responseObject=SuccessResponse.class, since="3.0.0") -public class DeleteTrafficTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficTypeCmd.class.getName()); - - private static final String s_name = "deletetraffictyperesponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="physical_network_traffic_types") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="traffic type id") - private Long id; - - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public Long getId() { - return id; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - boolean result = _networkService.deletePhysicalNetworkTrafficType(getId()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic type"); - } - } - - @Override - public String getEventDescription() { - return "Deleting Traffic Type: " + getId(); - } - - @Override - public String getEventType() { - return EventTypes.EVENT_TRAFFIC_TYPE_DELETE; - } - - @Override - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.TrafficType; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/com/cloud/api/commands/ListTrafficTypesCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/ListTrafficTypesCmd.java b/api/src/com/cloud/api/commands/ListTrafficTypesCmd.java deleted file mode 100755 index 17bd32d..0000000 --- a/api/src/com/cloud/api/commands/ListTrafficTypesCmd.java +++ /dev/null @@ -1,88 +0,0 @@ -// 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 com.cloud.api.commands; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseListCmd; -import org.apache.cloudstack.api.IdentityMapper; -import org.apache.cloudstack.api.Implementation; -import org.apache.cloudstack.api.Parameter; -import com.cloud.api.response.ListResponse; -import com.cloud.api.response.ProviderResponse; -import com.cloud.api.response.TrafficTypeResponse; -import com.cloud.network.PhysicalNetworkTrafficType; -import com.cloud.user.Account; -import com.cloud.utils.Pair; - - -@Implementation(description="Lists traffic types of a given physical network.", responseObject=ProviderResponse.class, since="3.0.0") -public class ListTrafficTypesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficTypesCmd.class.getName()); - private static final String _name = "listtraffictypesresponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="physical_network") - @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") - private Long physicalNetworkId; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public void setPhysicalNetworkId(Long physicalNetworkId) { - this.physicalNetworkId = physicalNetworkId; - } - - public Long getPhysicalNetworkId() { - return physicalNetworkId; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - @Override - public String getCommandName() { - return _name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId()); - ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>(); - List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>(); - for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) { - TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType); - trafficTypesResponses.add(trafficTypeResponse); - } - - response.setResponses(trafficTypesResponses, trafficTypes.second()); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/org/apache/cloudstack/api/admin/usage/command/AddTrafficTypeCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/usage/command/AddTrafficTypeCmd.java b/api/src/org/apache/cloudstack/api/admin/usage/command/AddTrafficTypeCmd.java new file mode 100644 index 0000000..6135741 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/usage/command/AddTrafficTypeCmd.java @@ -0,0 +1,158 @@ +// 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.admin.usage.command; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.IdentityMapper; +import org.apache.cloudstack.api.Implementation; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import com.cloud.api.response.TrafficTypeResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.PhysicalNetworkTrafficType; +import com.cloud.user.Account; +import com.cloud.user.UserContext; + +@Implementation(description="Adds traffic type to a physical network", responseObject=TrafficTypeResponse.class, since="3.0.0") +public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { + public static final Logger s_logger = Logger.getLogger(AddTrafficTypeCmd.class.getName()); + + private static final String s_name = "addtraffictyperesponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") + private Long physicalNetworkId; + + @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the trafficType to be added to the physical network") + private String trafficType; + + @Parameter(name=ApiConstants.XEN_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a XenServer host") + private String xenLabel; + + @Parameter(name=ApiConstants.KVM_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a KVM host") + private String kvmLabel; + + @Parameter(name=ApiConstants.VMWARE_NETWORK_LABEL, type=CommandType.STRING, description="The network name label of the physical device dedicated to this traffic on a VMware host") + private String vmwareLabel; + + @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="The VLAN id to be used for Management traffic by VMware host") + private String vlan; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEntityTable() { + return "physical_network_traffic_types"; + } + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + public String getTrafficType() { + return trafficType; + } + + public String getXenLabel() { + return xenLabel; + } + + public String getKvmLabel() { + return kvmLabel; + } + + public String getVmwareLabel() { + return vmwareLabel; + } + + public String getSimulatorLabel() { + //simulators will have no labels + return null; + } + + public void setVlan(String vlan) { + this.vlan = vlan; + } + + public String getVlan() { + return vlan; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("TrafficType Id: "+getEntityId()); + PhysicalNetworkTrafficType result = _networkService.getPhysicalNetworkTrafficType(getEntityId()); + if (result != null) { + TrafficTypeResponse response = _responseGenerator.createTrafficTypeResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + }else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); + } + } + + @Override + public void create() throws ResourceAllocationException { + PhysicalNetworkTrafficType result = _networkService.addTrafficTypeToPhysicalNetwork(getPhysicalNetworkId(), getTrafficType(), getXenLabel(), getKvmLabel(), getVmwareLabel(), getSimulatorLabel(), getVlan()); + if (result != null) { + setEntityId(result.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_TRAFFIC_TYPE_CREATE; + } + + @Override + public String getEventDescription() { + return "Adding physical network traffic type: " + getEntityId(); + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.TrafficType; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/org/apache/cloudstack/api/admin/usage/command/DeleteTrafficTypeCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/usage/command/DeleteTrafficTypeCmd.java b/api/src/org/apache/cloudstack/api/admin/usage/command/DeleteTrafficTypeCmd.java new file mode 100644 index 0000000..a7a2b7d --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/usage/command/DeleteTrafficTypeCmd.java @@ -0,0 +1,95 @@ +// 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.admin.usage.command; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.IdentityMapper; +import org.apache.cloudstack.api.Implementation; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +@Implementation(description="Deletes traffic type of a physical network", responseObject=SuccessResponse.class, since="3.0.0") +public class DeleteTrafficTypeCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeleteTrafficTypeCmd.class.getName()); + + private static final String s_name = "deletetraffictyperesponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="physical_network_traffic_types") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="traffic type id") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + boolean result = _networkService.deletePhysicalNetworkTrafficType(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + }else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic type"); + } + } + + @Override + public String getEventDescription() { + return "Deleting Traffic Type: " + getId(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_TRAFFIC_TYPE_DELETE; + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.TrafficType; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/api/src/org/apache/cloudstack/api/admin/usage/command/ListTrafficTypesCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/usage/command/ListTrafficTypesCmd.java b/api/src/org/apache/cloudstack/api/admin/usage/command/ListTrafficTypesCmd.java new file mode 100755 index 0000000..d3fe699 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/usage/command/ListTrafficTypesCmd.java @@ -0,0 +1,88 @@ +// 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.admin.usage.command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.IdentityMapper; +import org.apache.cloudstack.api.Implementation; +import org.apache.cloudstack.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.ProviderResponse; +import com.cloud.api.response.TrafficTypeResponse; +import com.cloud.network.PhysicalNetworkTrafficType; +import com.cloud.user.Account; +import com.cloud.utils.Pair; + + +@Implementation(description="Lists traffic types of a given physical network.", responseObject=ProviderResponse.class, since="3.0.0") +public class ListTrafficTypesCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(ListTrafficTypesCmd.class.getName()); + private static final String _name = "listtraffictypesresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") + private Long physicalNetworkId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public void setPhysicalNetworkId(Long physicalNetworkId) { + this.physicalNetworkId = physicalNetworkId; + } + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId()); + ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>(); + List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>(); + for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) { + TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType); + trafficTypesResponses.add(trafficTypeResponse); + } + + response.setResponses(trafficTypesResponses, trafficTypes.second()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bbe82e8/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index de7cc2a..4731bfc 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -357,9 +357,9 @@ listNetworkServiceProviders=org.apache.cloudstack.api.admin.network.command.List updateNetworkServiceProvider=org.apache.cloudstack.api.admin.network.command.UpdateNetworkServiceProviderCmd;1 #### Physical Network Traffic Type commands -addTrafficType=com.cloud.api.commands.AddTrafficTypeCmd;1 -deleteTrafficType=com.cloud.api.commands.DeleteTrafficTypeCmd;1 -listTrafficTypes=com.cloud.api.commands.ListTrafficTypesCmd;1 +addTrafficType=org.apache.cloudstack.api.admin.usage.command.AddTrafficTypeCmd;1 +deleteTrafficType=org.apache.cloudstack.api.admin.usage.command.DeleteTrafficTypeCmd;1 +listTrafficTypes=org.apache.cloudstack.api.admin.usage.command.ListTrafficTypesCmd;1 updateTrafficType=com.cloud.api.commands.UpdateTrafficTypeCmd;1 listTrafficTypeImplementors=com.cloud.api.commands.ListTrafficTypeImplementorsCmd;1
