api_refactor: capacity, hypvsr, alert and cert apis

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/089db9c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/089db9c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/089db9c6

Branch: refs/heads/api_refactoring
Commit: 089db9c6314a050cf0d09d4ad04f395f81caf609
Parents: 780eb95
Author: Rohit Yadav <[email protected]>
Authored: Thu Dec 6 11:25:56 2012 -0800
Committer: Rohit Yadav <[email protected]>
Committed: Thu Dec 6 11:25:56 2012 -0800

----------------------------------------------------------------------
 api/src/com/cloud/api/commands/ListAlertsCmd.java  |   93 ----------
 .../com/cloud/api/commands/ListCapacityCmd.java    |  138 ---------------
 .../api/commands/UploadCustomCertificateCmd.java   |  110 ------------
 api/src/com/cloud/server/ManagementService.java    |    6 +-
 .../api/admin/resource/command/ListAlertsCmd.java  |   93 ++++++++++
 .../admin/resource/command/ListCapacityCmd.java    |  138 +++++++++++++++
 .../command/UploadCustomCertificateCmd.java        |  110 ++++++++++++
 .../hypervisor/command/ListHypervisorsCmd.java     |   85 ---------
 .../user/resource/command/ListHypervisorsCmd.java  |   85 +++++++++
 client/tomcatconf/commands.properties.in           |    8 +-
 .../src/com/cloud/server/ManagementServerImpl.java |    6 +-
 11 files changed, 436 insertions(+), 436 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/com/cloud/api/commands/ListAlertsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListAlertsCmd.java 
b/api/src/com/cloud/api/commands/ListAlertsCmd.java
deleted file mode 100644
index 00ee59f..0000000
--- a/api/src/com/cloud/api/commands/ListAlertsCmd.java
+++ /dev/null
@@ -1,93 +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 com.cloud.alert.Alert;
-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.AlertResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.utils.Pair;
-
-@Implementation(description = "Lists all alerts.", responseObject = 
AlertResponse.class)
-public class ListAlertsCmd extends BaseListCmd {
-
-    public static final Logger s_logger = 
Logger.getLogger(ListAlertsCmd.class.getName());
-
-    private static final String s_name = "listalertsresponse";
-
-    // ///////////////////////////////////////////////////
-    // ////////////// API parameters /////////////////////
-    // ///////////////////////////////////////////////////
-
-    @IdentityMapper(entityTableName="alert")
-    @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = 
"the ID of the alert")
-    private Long id;
-
-    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, 
description = "list by alert type")
-    private String type;
-
-    // ///////////////////////////////////////////////////
-    // ///////////////// Accessors ///////////////////////
-    // ///////////////////////////////////////////////////
-
-    public Long getId() {
-        return id;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    // ///////////////////////////////////////////////////
-    // ///////////// API Implementation///////////////////
-    // ///////////////////////////////////////////////////
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public void execute() {
-        Pair<List<? extends Alert>, Integer> result = 
_mgr.searchForAlerts(this);
-        ListResponse<AlertResponse> response = new 
ListResponse<AlertResponse>();
-        List<AlertResponse> alertResponseList = new ArrayList<AlertResponse>();
-        for (Alert alert : result.first()) {
-            AlertResponse alertResponse = new AlertResponse();
-            alertResponse.setId(alert.getId());
-            alertResponse.setAlertType(alert.getType());
-            alertResponse.setDescription(alert.getSubject());
-            alertResponse.setLastSent(alert.getLastSent());
-
-            alertResponse.setObjectName("alert");
-            alertResponseList.add(alertResponse);
-        }
-
-        response.setResponses(alertResponseList, result.second());
-        response.setResponseName(getCommandName());
-        this.setResponseObject(response);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/com/cloud/api/commands/ListCapacityCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListCapacityCmd.java 
b/api/src/com/cloud/api/commands/ListCapacityCmd.java
deleted file mode 100755
index ecb590a..0000000
--- a/api/src/com/cloud/api/commands/ListCapacityCmd.java
+++ /dev/null
@@ -1,138 +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.text.DecimalFormat;
-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.CapacityResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.capacity.Capacity;
-import com.cloud.exception.InvalidParameterValueException;
-
-@Implementation(description="Lists all the system wide capacities.", 
responseObject=CapacityResponse.class)
-public class ListCapacityCmd extends BaseListCmd {
-
-    public static final Logger s_logger = 
Logger.getLogger(ListCapacityCmd.class.getName());
-    private static final DecimalFormat s_percentFormat = new 
DecimalFormat("##.##");
-
-    private static final String s_name = "listcapacityresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-    @IdentityMapper(entityTableName="data_center")
-    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, 
description="lists capacity by the Zone ID")
-    private Long zoneId;
-
-    @IdentityMapper(entityTableName="host_pod_ref")
-    @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, 
description="lists capacity by the Pod ID")
-    private Long podId;
-
-    @IdentityMapper(entityTableName="cluster")
-    @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, 
since="3.0.0", description="lists capacity by the Cluster ID")
-    private Long clusterId;
-
-    @Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, 
since="3.0.0", description="recalculate capacities and fetch the latest")
-    private Boolean fetchLatest;
-
-    @Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, 
description="lists capacity by type" +
-                                                                             
"* CAPACITY_TYPE_MEMORY = 0" +
-                                                                             
"* CAPACITY_TYPE_CPU = 1" +
-                                                                             
"* CAPACITY_TYPE_STORAGE = 2" +
-                                                                             
"* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" +
-                                                                             
"* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" +
-                                                                             
"* CAPACITY_TYPE_PRIVATE_IP = 5" +
-                                                                             
"* CAPACITY_TYPE_SECONDARY_STORAGE = 6" +
-                                                                             
"* CAPACITY_TYPE_VLAN = 7" +
-                                                                             
"* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" +
-                                                                             
"* CAPACITY_TYPE_LOCAL_STORAGE = 9.")
-
-    private Integer type;
-
-    @Parameter(name=ApiConstants.SORT_BY, type=CommandType.STRING, 
since="3.0.0", description="Sort the results. Available values: Usage")
-    private String sortBy;
-
-    /////////////////////////////////////////////////////
-    /////////////////// Accessors ///////////////////////
-    /////////////////////////////////////////////////////
-
-    public Long getZoneId() {
-        return zoneId;
-    }
-
-    public Long getPodId() {
-        return podId;
-    }
-
-    public Long getClusterId() {
-        return clusterId;
-    }
-
-    public Boolean getFetchLatest() {
-        return fetchLatest;
-    }
-
-    public Integer getType() {
-        return type;
-    }
-
-    public String getSortBy() {
-        if (sortBy != null) {
-            if (sortBy.equalsIgnoreCase("usage")) {
-                return sortBy;
-            } else {
-                throw new InvalidParameterValueException("Only value supported 
for sortBy parameter is : usage");
-            }
-        }
-
-        return null;
-    }
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public void execute(){
-        List<? extends Capacity> result = null;
-        if (getSortBy() != null) {
-            result = _mgr.listTopConsumedResources(this);
-        } else {
-            result = _mgr.listCapacities(this);
-        }
-
-        ListResponse<CapacityResponse> response = new 
ListResponse<CapacityResponse>();
-        List<CapacityResponse> capacityResponses = 
_responseGenerator.createCapacityResponse(result, s_percentFormat);
-        response.setResponses(capacityResponses);
-        response.setResponseName(getCommandName());
-        this.setResponseObject(response);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/com/cloud/api/commands/UploadCustomCertificateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UploadCustomCertificateCmd.java 
b/api/src/com/cloud/api/commands/UploadCustomCertificateCmd.java
deleted file mode 100644
index d297dfa..0000000
--- a/api/src/com/cloud/api/commands/UploadCustomCertificateCmd.java
+++ /dev/null
@@ -1,110 +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.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.CustomCertificateResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.user.Account;
-
-@Implementation(responseObject=CustomCertificateResponse.class, 
description="Uploads a custom certificate for the console proxy VMs to use for 
SSL. Can be used to upload a single certificate signed by a known CA. Can also 
be used, through multiple calls, to upload a chain of certificates from CA to 
the custom certificate itself.")
-public class UploadCustomCertificateCmd extends BaseAsyncCmd {
-    public static final Logger s_logger = 
Logger.getLogger(UploadCustomCertificateCmd.class.getName());
-
-    private static final String s_name = "uploadcustomcertificateresponse";
-
-    
@Parameter(name=ApiConstants.CERTIFICATE,type=CommandType.STRING,required=true,description="The
 certificate to be uploaded.", length=65535)
-    private String certificate;
-
-    
@Parameter(name=ApiConstants.ID,type=CommandType.INTEGER,required=false,description="An
 integer providing the location in a chain that the certificate will hold. 
Usually, this can be left empty. When creating a chain, the top level 
certificate should have an ID of 1, with each step in the chain incrementing by 
one. Example, CA with id = 1, Intermediate CA with id = 2, Site certificate 
with ID = 3")
-    private Integer index;
-
-    
@Parameter(name=ApiConstants.NAME,type=CommandType.STRING,required=false,description="A
 name / alias for the certificate.")
-    private String alias;
-
-    
@Parameter(name=ApiConstants.PRIVATE_KEY,type=CommandType.STRING,required=false,description="The
 private key for the attached certificate.", length=65535)
-    private String privateKey;
-
-    
@Parameter(name=ApiConstants.DOMAIN_SUFFIX,type=CommandType.STRING,required=true,description="DNS
 domain suffix that the certificate is granted for.")
-    private String domainSuffix;
-
-    public String getCertificate() {
-        return certificate;
-    }
-
-    public String getPrivateKey() {
-        return privateKey;
-    }
-
-    public String getDomainSuffix() {
-        return domainSuffix;
-    }
-
-    public Integer getCertIndex() {
-        return index;
-    }
-
-    public String getAlias() {
-        return alias;
-    }
-
-    @Override
-    public String getEventType() {
-        return EventTypes.EVENT_UPLOAD_CUSTOM_CERTIFICATE;
-    }
-
-    @Override
-    public String getEventDescription() {
-        return  ("Uploading custom certificate to the db, and applying it to 
all the cpvms in the system");
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    public static String getResultObjectName() {
-        return "certificate";
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
-    }
-
-    @Override
-    public void execute(){
-        String result = _mgr.uploadCertificate(this);
-        if (result != null) {
-            CustomCertificateResponse response = new 
CustomCertificateResponse();
-            response.setResponseName(getCommandName());
-            response.setResultMessage(result);
-            response.setObjectName("customcertificate");
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
upload custom certificate");
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/com/cloud/server/ManagementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/ManagementService.java 
b/api/src/com/cloud/server/ManagementService.java
index db5f8ba..5ee9054 100755
--- a/api/src/com/cloud/server/ManagementService.java
+++ b/api/src/com/cloud/server/ManagementService.java
@@ -28,6 +28,8 @@ import 
org.apache.cloudstack.api.admin.cluster.command.ListClustersCmd;
 import org.apache.cloudstack.api.admin.host.command.ListHostsCmd;
 import org.apache.cloudstack.api.admin.host.command.UpdateHostPasswordCmd;
 import org.apache.cloudstack.api.admin.pod.command.ListPodsByCmd;
+import org.apache.cloudstack.api.admin.resource.command.ListAlertsCmd;
+import org.apache.cloudstack.api.admin.resource.command.ListCapacityCmd;
 import org.apache.cloudstack.api.admin.router.command.ListRoutersCmd;
 import org.apache.cloudstack.api.user.address.command.ListPublicIpAddressesCmd;
 import org.apache.cloudstack.api.user.config.command.ListCapabilitiesCmd;
@@ -41,9 +43,7 @@ import 
org.apache.cloudstack.api.user.volume.command.ExtractVolumeCmd;
 import org.apache.cloudstack.api.user.template.command.ListTemplatesCmd;
 import org.apache.cloudstack.api.user.template.command.UpdateTemplateCmd;
 import org.apache.cloudstack.api.user.vm.command.GetVMPasswordCmd;
-import com.cloud.api.commands.ListAlertsCmd;
 import org.apache.cloudstack.api.user.job.command.ListAsyncJobsCmd;
-import com.cloud.api.commands.ListCapacityCmd;
 import org.apache.cloudstack.api.admin.config.command.ListCfgsByCmd;
 import org.apache.cloudstack.api.user.event.command.ListEventsCmd;
 import org.apache.cloudstack.api.user.guest.command.ListGuestOsCategoriesCmd;
@@ -61,7 +61,7 @@ import 
org.apache.cloudstack.api.admin.domain.command.UpdateDomainCmd;
 import org.apache.cloudstack.api.user.iso.command.UpdateIsoCmd;
 import org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroupCmd;
 import org.apache.cloudstack.api.admin.systemvm.command.UpgradeSystemVMCmd;
-import com.cloud.api.commands.UploadCustomCertificateCmd;
+import 
org.apache.cloudstack.api.admin.resource.command.UploadCustomCertificateCmd;
 import com.cloud.api.view.vo.DomainRouterJoinVO;
 import com.cloud.async.AsyncJob;
 import com.cloud.capacity.Capacity;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/org/apache/cloudstack/api/admin/resource/command/ListAlertsCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/resource/command/ListAlertsCmd.java 
b/api/src/org/apache/cloudstack/api/admin/resource/command/ListAlertsCmd.java
new file mode 100644
index 0000000..d82e456
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/resource/command/ListAlertsCmd.java
@@ -0,0 +1,93 @@
+// 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.resource.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.alert.Alert;
+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.AlertResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.utils.Pair;
+
+@Implementation(description = "Lists all alerts.", responseObject = 
AlertResponse.class)
+public class ListAlertsCmd extends BaseListCmd {
+
+    public static final Logger s_logger = 
Logger.getLogger(ListAlertsCmd.class.getName());
+
+    private static final String s_name = "listalertsresponse";
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="alert")
+    @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = 
"the ID of the alert")
+    private Long id;
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, 
description = "list by alert type")
+    private String type;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute() {
+        Pair<List<? extends Alert>, Integer> result = 
_mgr.searchForAlerts(this);
+        ListResponse<AlertResponse> response = new 
ListResponse<AlertResponse>();
+        List<AlertResponse> alertResponseList = new ArrayList<AlertResponse>();
+        for (Alert alert : result.first()) {
+            AlertResponse alertResponse = new AlertResponse();
+            alertResponse.setId(alert.getId());
+            alertResponse.setAlertType(alert.getType());
+            alertResponse.setDescription(alert.getSubject());
+            alertResponse.setLastSent(alert.getLastSent());
+
+            alertResponse.setObjectName("alert");
+            alertResponseList.add(alertResponse);
+        }
+
+        response.setResponses(alertResponseList, result.second());
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/org/apache/cloudstack/api/admin/resource/command/ListCapacityCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/resource/command/ListCapacityCmd.java 
b/api/src/org/apache/cloudstack/api/admin/resource/command/ListCapacityCmd.java
new file mode 100755
index 0000000..39cbddf
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/resource/command/ListCapacityCmd.java
@@ -0,0 +1,138 @@
+// 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.resource.command;
+
+import java.text.DecimalFormat;
+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.CapacityResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.capacity.Capacity;
+import com.cloud.exception.InvalidParameterValueException;
+
+@Implementation(description="Lists all the system wide capacities.", 
responseObject=CapacityResponse.class)
+public class ListCapacityCmd extends BaseListCmd {
+
+    public static final Logger s_logger = 
Logger.getLogger(ListCapacityCmd.class.getName());
+    private static final DecimalFormat s_percentFormat = new 
DecimalFormat("##.##");
+
+    private static final String s_name = "listcapacityresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="data_center")
+    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, 
description="lists capacity by the Zone ID")
+    private Long zoneId;
+
+    @IdentityMapper(entityTableName="host_pod_ref")
+    @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, 
description="lists capacity by the Pod ID")
+    private Long podId;
+
+    @IdentityMapper(entityTableName="cluster")
+    @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, 
since="3.0.0", description="lists capacity by the Cluster ID")
+    private Long clusterId;
+
+    @Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, 
since="3.0.0", description="recalculate capacities and fetch the latest")
+    private Boolean fetchLatest;
+
+    @Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, 
description="lists capacity by type" +
+                                                                             
"* CAPACITY_TYPE_MEMORY = 0" +
+                                                                             
"* CAPACITY_TYPE_CPU = 1" +
+                                                                             
"* CAPACITY_TYPE_STORAGE = 2" +
+                                                                             
"* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" +
+                                                                             
"* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" +
+                                                                             
"* CAPACITY_TYPE_PRIVATE_IP = 5" +
+                                                                             
"* CAPACITY_TYPE_SECONDARY_STORAGE = 6" +
+                                                                             
"* CAPACITY_TYPE_VLAN = 7" +
+                                                                             
"* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" +
+                                                                             
"* CAPACITY_TYPE_LOCAL_STORAGE = 9.")
+
+    private Integer type;
+
+    @Parameter(name=ApiConstants.SORT_BY, type=CommandType.STRING, 
since="3.0.0", description="Sort the results. Available values: Usage")
+    private String sortBy;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getZoneId() {
+        return zoneId;
+    }
+
+    public Long getPodId() {
+        return podId;
+    }
+
+    public Long getClusterId() {
+        return clusterId;
+    }
+
+    public Boolean getFetchLatest() {
+        return fetchLatest;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public String getSortBy() {
+        if (sortBy != null) {
+            if (sortBy.equalsIgnoreCase("usage")) {
+                return sortBy;
+            } else {
+                throw new InvalidParameterValueException("Only value supported 
for sortBy parameter is : usage");
+            }
+        }
+
+        return null;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+        List<? extends Capacity> result = null;
+        if (getSortBy() != null) {
+            result = _mgr.listTopConsumedResources(this);
+        } else {
+            result = _mgr.listCapacities(this);
+        }
+
+        ListResponse<CapacityResponse> response = new 
ListResponse<CapacityResponse>();
+        List<CapacityResponse> capacityResponses = 
_responseGenerator.createCapacityResponse(result, s_percentFormat);
+        response.setResponses(capacityResponses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/org/apache/cloudstack/api/admin/resource/command/UploadCustomCertificateCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/resource/command/UploadCustomCertificateCmd.java
 
b/api/src/org/apache/cloudstack/api/admin/resource/command/UploadCustomCertificateCmd.java
new file mode 100644
index 0000000..76be280
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/resource/command/UploadCustomCertificateCmd.java
@@ -0,0 +1,110 @@
+// 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.resource.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.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.CustomCertificateResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+
+@Implementation(responseObject=CustomCertificateResponse.class, 
description="Uploads a custom certificate for the console proxy VMs to use for 
SSL. Can be used to upload a single certificate signed by a known CA. Can also 
be used, through multiple calls, to upload a chain of certificates from CA to 
the custom certificate itself.")
+public class UploadCustomCertificateCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = 
Logger.getLogger(UploadCustomCertificateCmd.class.getName());
+
+    private static final String s_name = "uploadcustomcertificateresponse";
+
+    
@Parameter(name=ApiConstants.CERTIFICATE,type=CommandType.STRING,required=true,description="The
 certificate to be uploaded.", length=65535)
+    private String certificate;
+
+    
@Parameter(name=ApiConstants.ID,type=CommandType.INTEGER,required=false,description="An
 integer providing the location in a chain that the certificate will hold. 
Usually, this can be left empty. When creating a chain, the top level 
certificate should have an ID of 1, with each step in the chain incrementing by 
one. Example, CA with id = 1, Intermediate CA with id = 2, Site certificate 
with ID = 3")
+    private Integer index;
+
+    
@Parameter(name=ApiConstants.NAME,type=CommandType.STRING,required=false,description="A
 name / alias for the certificate.")
+    private String alias;
+
+    
@Parameter(name=ApiConstants.PRIVATE_KEY,type=CommandType.STRING,required=false,description="The
 private key for the attached certificate.", length=65535)
+    private String privateKey;
+
+    
@Parameter(name=ApiConstants.DOMAIN_SUFFIX,type=CommandType.STRING,required=true,description="DNS
 domain suffix that the certificate is granted for.")
+    private String domainSuffix;
+
+    public String getCertificate() {
+        return certificate;
+    }
+
+    public String getPrivateKey() {
+        return privateKey;
+    }
+
+    public String getDomainSuffix() {
+        return domainSuffix;
+    }
+
+    public Integer getCertIndex() {
+        return index;
+    }
+
+    public String getAlias() {
+        return alias;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_UPLOAD_CUSTOM_CERTIFICATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return  ("Uploading custom certificate to the db, and applying it to 
all the cpvms in the system");
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public static String getResultObjectName() {
+        return "certificate";
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public void execute(){
+        String result = _mgr.uploadCertificate(this);
+        if (result != null) {
+            CustomCertificateResponse response = new 
CustomCertificateResponse();
+            response.setResponseName(getCommandName());
+            response.setResultMessage(result);
+            response.setObjectName("customcertificate");
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
upload custom certificate");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/org/apache/cloudstack/api/user/hypervisor/command/ListHypervisorsCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/user/hypervisor/command/ListHypervisorsCmd.java
 
b/api/src/org/apache/cloudstack/api/user/hypervisor/command/ListHypervisorsCmd.java
deleted file mode 100644
index 2055f99..0000000
--- 
a/api/src/org/apache/cloudstack/api/user/hypervisor/command/ListHypervisorsCmd.java
+++ /dev/null
@@ -1,85 +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 org.apache.cloudstack.api.user.hypervisor.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cloudstack.api.admin.router.command.UpgradeRouterCmd;
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-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 com.cloud.api.response.HypervisorResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.user.Account;
-
-@Implementation(description = "List hypervisors", responseObject = 
HypervisorResponse.class)
-public class ListHypervisorsCmd extends BaseCmd {
-    public static final Logger s_logger = 
Logger.getLogger(UpgradeRouterCmd.class.getName());
-    private static final String s_name = "listhypervisorsresponse";
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    // ///////////////////////////////////////////////////
-    // ////////////// API parameters /////////////////////
-    // ///////////////////////////////////////////////////
-
-    @IdentityMapper(entityTableName="data_center")
-    @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.LONG, 
description = "the zone id for listing hypervisors.")
-    private Long zoneId;
-
-    // ///////////////////////////////////////////////////
-    // ///////////////// Accessors ///////////////////////
-    // ///////////////////////////////////////////////////
-
-    public Long getZoneId() {
-        return this.zoneId;
-    }
-
-    // ///////////////////////////////////////////////////
-    // ///////////// API Implementation///////////////////
-    // ///////////////////////////////////////////////////
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
-
-    @Override
-    public void execute() {
-        List<String> result = _mgr.getHypervisors(getZoneId());
-        ListResponse<HypervisorResponse> response = new 
ListResponse<HypervisorResponse>();
-        ArrayList<HypervisorResponse> responses = new 
ArrayList<HypervisorResponse>();
-        if (result != null) {
-            for (String hypervisor : result) {
-                HypervisorResponse hypervisorResponse = new 
HypervisorResponse();
-                hypervisorResponse.setName(hypervisor);
-                hypervisorResponse.setObjectName("hypervisor");
-                responses.add(hypervisorResponse);
-            }
-        }
-        response.setResponses(responses);
-        response.setResponseName(getCommandName());
-        this.setResponseObject(response);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/api/src/org/apache/cloudstack/api/user/resource/command/ListHypervisorsCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/user/resource/command/ListHypervisorsCmd.java
 
b/api/src/org/apache/cloudstack/api/user/resource/command/ListHypervisorsCmd.java
new file mode 100644
index 0000000..2f78aa8
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/user/resource/command/ListHypervisorsCmd.java
@@ -0,0 +1,85 @@
+// 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.user.resource.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.api.admin.router.command.UpgradeRouterCmd;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+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 com.cloud.api.response.HypervisorResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.user.Account;
+
+@Implementation(description = "List hypervisors", responseObject = 
HypervisorResponse.class)
+public class ListHypervisorsCmd extends BaseCmd {
+    public static final Logger s_logger = 
Logger.getLogger(UpgradeRouterCmd.class.getName());
+    private static final String s_name = "listhypervisorsresponse";
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="data_center")
+    @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.LONG, 
description = "the zone id for listing hypervisors.")
+    private Long zoneId;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public Long getZoneId() {
+        return this.zoneId;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute() {
+        List<String> result = _mgr.getHypervisors(getZoneId());
+        ListResponse<HypervisorResponse> response = new 
ListResponse<HypervisorResponse>();
+        ArrayList<HypervisorResponse> responses = new 
ArrayList<HypervisorResponse>();
+        if (result != null) {
+            for (String hypervisor : result) {
+                HypervisorResponse hypervisorResponse = new 
HypervisorResponse();
+                hypervisorResponse.setName(hypervisor);
+                hypervisorResponse.setObjectName("hypervisor");
+                responses.add(hypervisorResponse);
+            }
+        }
+        response.setResponses(responses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in 
b/client/tomcatconf/commands.properties.in
index d825505..db5a134 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -219,10 +219,10 @@ 
listEvents=org.apache.cloudstack.api.user.event.command.ListEventsCmd;15
 
listEventTypes=org.apache.cloudstack.api.user.event.command.ListEventTypesCmd;15
 
 #### alerts commands
-listAlerts=com.cloud.api.commands.ListAlertsCmd;3
+listAlerts=org.apache.cloudstack.api.admin.resource.command.ListAlertsCmd;3
 
 #### system capacity commands
-listCapacity=com.cloud.api.commands.ListCapacityCmd;3
+listCapacity=org.apache.cloudstack.api.admin.resource.command.ListCapacityCmd;3
 
 #### swift commands^M
 addSwift=org.apache.cloudstack.api.admin.swift.command.AddSwiftCmd;1
@@ -288,10 +288,10 @@ 
updateInstanceGroup=org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroup
 
listInstanceGroups=org.apache.cloudstack.api.user.vmgroup.command.ListVMGroupsCmd;15
 
 ### Certificate commands
-uploadCustomCertificate=com.cloud.api.commands.UploadCustomCertificateCmd;1
+uploadCustomCertificate=org.apache.cloudstack.api.admin.resource.command.UploadCustomCertificateCmd;1
 
 ### other commands
-listHypervisors=org.apache.cloudstack.api.user.hypervisor.command.ListHypervisorsCmd;15
+listHypervisors=org.apache.cloudstack.api.user.resource.command.ListHypervisorsCmd;15
 
 ### VPN
 
createRemoteAccessVpn=org.apache.cloudstack.api.user.vpn.command.CreateRemoteAccessVpnCmd;15

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/089db9c6/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java 
b/server/src/com/cloud/server/ManagementServerImpl.java
index 1d7c486..fba6ac9 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -44,6 +44,7 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.cloudstack.api.admin.cluster.command.ListClustersCmd;
 import org.apache.cloudstack.api.admin.config.command.ListCfgsByCmd;
+import org.apache.cloudstack.api.admin.resource.command.ListAlertsCmd;
 import org.apache.cloudstack.api.admin.router.command.ListRoutersCmd;
 import org.apache.cloudstack.api.user.config.command.ListCapabilitiesCmd;
 import org.apache.cloudstack.api.user.guest.command.ListGuestOsCategoriesCmd;
@@ -78,8 +79,7 @@ import 
org.apache.cloudstack.api.user.ssh.command.CreateSSHKeyPairCmd;
 import org.apache.cloudstack.api.admin.systemvm.command.DestroySystemVmCmd;
 import org.apache.cloudstack.api.user.volume.command.ExtractVolumeCmd;
 import org.apache.cloudstack.api.user.vm.command.GetVMPasswordCmd;
-import com.cloud.api.commands.ListAlertsCmd;
-import com.cloud.api.commands.ListCapacityCmd;
+import org.apache.cloudstack.api.admin.resource.command.ListCapacityCmd;
 import org.apache.cloudstack.api.user.event.command.ListEventsCmd;
 import org.apache.cloudstack.api.admin.host.command.ListHostsCmd;
 import org.apache.cloudstack.api.admin.pod.command.ListPodsByCmd;
@@ -96,7 +96,7 @@ import 
org.apache.cloudstack.api.user.iso.command.UpdateIsoCmd;
 import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
 import org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroupCmd;
 import org.apache.cloudstack.api.admin.systemvm.command.UpgradeSystemVMCmd;
-import com.cloud.api.commands.UploadCustomCertificateCmd;
+import 
org.apache.cloudstack.api.admin.resource.command.UploadCustomCertificateCmd;
 import com.cloud.api.response.ExtractResponse;
 import com.cloud.api.view.vo.DomainRouterJoinVO;
 import com.cloud.async.AsyncJob;

Reply via email to