api_refactor: refactor for autoscale 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/dd5a36fc Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/dd5a36fc Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/dd5a36fc Branch: refs/heads/api_refactoring Commit: dd5a36fcd2ebb373d627d061e67f16c304f4ae5b Parents: 2121fbd Author: Rohit Yadav <[email protected]> Authored: Tue Dec 4 11:42:07 2012 -0800 Committer: Rohit Yadav <[email protected]> Committed: Tue Dec 4 11:42:07 2012 -0800 ---------------------------------------------------------------------- .../com/cloud/api/commands/CreateCounterCmd.java | 120 --------------- .../com/cloud/api/commands/DeleteCounterCmd.java | 103 ------------- api/src/com/cloud/network/as/AutoScaleService.java | 2 +- .../admin/autoscale/command/CreateCounterCmd.java | 120 +++++++++++++++ .../admin/autoscale/command/DeleteCounterCmd.java | 103 +++++++++++++ client/tomcatconf/commands.properties.in | 4 +- .../com/cloud/network/as/AutoScaleManagerImpl.java | 2 +- 7 files changed, 227 insertions(+), 227 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/api/src/com/cloud/api/commands/CreateCounterCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/CreateCounterCmd.java b/api/src/com/cloud/api/commands/CreateCounterCmd.java deleted file mode 100644 index f446519..0000000 --- a/api/src/com/cloud/api/commands/CreateCounterCmd.java +++ /dev/null @@ -1,120 +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.Implementation; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.api.response.CounterResponse; -import com.cloud.async.AsyncJob; -import com.cloud.event.EventTypes; -import com.cloud.network.as.Counter; -import com.cloud.user.Account; - -@Implementation(description = "Adds metric counter", responseObject = CounterResponse.class) -public class CreateCounterCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName()); - private static final String s_name = "counterresponse"; - - // /////////////////////////////////////////////////// - // ////////////// API parameters ///////////////////// - // /////////////////////////////////////////////////// - - @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Name of the counter.") - private String name; - - @Parameter(name = ApiConstants.SOURCE, type = CommandType.STRING, required = true, description = "Source of the counter.") - private String source; - - @Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "Value of the counter e.g. oid in case of snmp.") - private String value; - - // ///////////////////////////////////////////////// - // ///////////////// Accessors /////////////////////// - // /////////////////////////////////////////////////// - - public String getName() { - return name; - } - - public String getSource() { - return source; - } - - public String getValue() { - return value; - } - - // /////////////////////////////////////////////////// - // ///////////// API Implementation/////////////////// - // /////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public void create() { - Counter ctr = null; - ctr = _autoScaleService.createCounter(this); - - if (ctr != null) { - this.setEntityId(ctr.getId()); - CounterResponse response = _responseGenerator.createCounterResponse(ctr); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Counter with name " + getName()); - } - } - - @Override - public void execute() { - } - - @Override - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.Counter; - } - - @Override - public String getEventType() { - return EventTypes.EVENT_COUNTER_CREATE; - } - - @Override - public String getEventDescription() { - return "creating a new Counter"; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public String getEntityTable() { - return "counter"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/api/src/com/cloud/api/commands/DeleteCounterCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/DeleteCounterCmd.java b/api/src/com/cloud/api/commands/DeleteCounterCmd.java deleted file mode 100644 index 2b2d7b2..0000000 --- a/api/src/com/cloud/api/commands/DeleteCounterCmd.java +++ /dev/null @@ -1,103 +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.exception.ResourceInUseException; -import com.cloud.user.Account; - -@Implementation(description = "Deletes a counter", responseObject = SuccessResponse.class) -public class DeleteCounterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName()); - private static final String s_name = "deletecounterresponse"; - - // /////////////////////////////////////////////////// - // ////////////// API parameters ///////////////////// - // /////////////////////////////////////////////////// - - @IdentityMapper(entityTableName = "counter") - @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the counter") - private Long id; - - // /////////////////////////////////////////////////// - // ///////////// API Implementation/////////////////// - // /////////////////////////////////////////////////// - - @Override - public void execute() { - boolean result = false; - try { - result = _autoScaleService.deleteCounter(getId()); - } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage()); - } - - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - s_logger.warn("Failed to delete counter with Id: " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete counter."); - } - } - - // /////////////////////////////////////////////////// - // ///////////////// Accessors /////////////////////// - // /////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - public Long getId() { - return id; - } - - @Override - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.Counter; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public String getEventType() { - return EventTypes.EVENT_COUNTER_DELETE; - } - - @Override - public String getEventDescription() { - return "Deleting a counter."; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/api/src/com/cloud/network/as/AutoScaleService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/as/AutoScaleService.java b/api/src/com/cloud/network/as/AutoScaleService.java index 3084868..a6b2f48 100644 --- a/api/src/com/cloud/network/as/AutoScaleService.java +++ b/api/src/com/cloud/network/as/AutoScaleService.java @@ -18,11 +18,11 @@ package com.cloud.network.as; import java.util.List; +import org.apache.cloudstack.api.admin.autoscale.command.CreateCounterCmd; import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScalePolicyCmd; import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmGroupCmd; import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmProfileCmd; import org.apache.cloudstack.api.user.autoscale.command.*; -import com.cloud.api.commands.CreateCounterCmd; import org.apache.cloudstack.api.user.autoscale.command.ListAutoScalePoliciesCmd; import org.apache.cloudstack.api.user.autoscale.command.ListConditionsCmd; import org.apache.cloudstack.api.user.autoscale.command.UpdateAutoScaleVmGroupCmd; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/api/src/org/apache/cloudstack/api/admin/autoscale/command/CreateCounterCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/autoscale/command/CreateCounterCmd.java b/api/src/org/apache/cloudstack/api/admin/autoscale/command/CreateCounterCmd.java new file mode 100644 index 0000000..1fb712e --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/autoscale/command/CreateCounterCmd.java @@ -0,0 +1,120 @@ +// 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.autoscale.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.Implementation; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import com.cloud.api.response.CounterResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.network.as.Counter; +import com.cloud.user.Account; + +@Implementation(description = "Adds metric counter", responseObject = CounterResponse.class) +public class CreateCounterCmd extends BaseAsyncCreateCmd { + public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName()); + private static final String s_name = "counterresponse"; + + // /////////////////////////////////////////////////// + // ////////////// API parameters ///////////////////// + // /////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Name of the counter.") + private String name; + + @Parameter(name = ApiConstants.SOURCE, type = CommandType.STRING, required = true, description = "Source of the counter.") + private String source; + + @Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "Value of the counter e.g. oid in case of snmp.") + private String value; + + // ///////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + public String getName() { + return name; + } + + public String getSource() { + return source; + } + + public String getValue() { + return value; + } + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void create() { + Counter ctr = null; + ctr = _autoScaleService.createCounter(this); + + if (ctr != null) { + this.setEntityId(ctr.getId()); + CounterResponse response = _responseGenerator.createCounterResponse(ctr); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Counter with name " + getName()); + } + } + + @Override + public void execute() { + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Counter; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_COUNTER_CREATE; + } + + @Override + public String getEventDescription() { + return "creating a new Counter"; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public String getEntityTable() { + return "counter"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/api/src/org/apache/cloudstack/api/admin/autoscale/command/DeleteCounterCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/autoscale/command/DeleteCounterCmd.java b/api/src/org/apache/cloudstack/api/admin/autoscale/command/DeleteCounterCmd.java new file mode 100644 index 0000000..161c60c --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/autoscale/command/DeleteCounterCmd.java @@ -0,0 +1,103 @@ +// 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.autoscale.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.exception.ResourceInUseException; +import com.cloud.user.Account; + +@Implementation(description = "Deletes a counter", responseObject = SuccessResponse.class) +public class DeleteCounterCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName()); + private static final String s_name = "deletecounterresponse"; + + // /////////////////////////////////////////////////// + // ////////////// API parameters ///////////////////// + // /////////////////////////////////////////////////// + + @IdentityMapper(entityTableName = "counter") + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the counter") + private Long id; + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + @Override + public void execute() { + boolean result = false; + try { + result = _autoScaleService.deleteCounter(getId()); + } catch (ResourceInUseException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage()); + } + + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + s_logger.warn("Failed to delete counter with Id: " + getId()); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete counter."); + } + } + + // /////////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + public Long getId() { + return id; + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Counter; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_COUNTER_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting a counter."; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index efa5cd9..c1ddf39 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -154,12 +154,12 @@ listLoadBalancerRuleInstances=org.apache.cloudstack.api.user.lb.command.ListLoad updateLoadBalancerRule=org.apache.cloudstack.api.user.lb.command.UpdateLoadBalancerRuleCmd;15 #### autoscale commands -createCounter = com.cloud.api.commands.CreateCounterCmd;1 +createCounter = org.apache.cloudstack.api.admin.autoscale.command.CreateCounterCmd;1 createCondition = org.apache.cloudstack.api.user.autoscale.command.CreateConditionCmd;15 createAutoScalePolicy=org.apache.cloudstack.api.user.autoscale.command.CreateAutoScalePolicyCmd;15 createAutoScaleVmProfile=org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmProfileCmd;15 createAutoScaleVmGroup=org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmGroupCmd;15 -deleteCounter = com.cloud.api.commands.DeleteCounterCmd;1 +deleteCounter = org.apache.cloudstack.api.admin.autoscale.command.DeleteCounterCmd;1 deleteCondition = org.apache.cloudstack.api.user.autoscale.command.DeleteConditionCmd;15 deleteAutoScalePolicy=org.apache.cloudstack.api.user.autoscale.command.DeleteAutoScalePolicyCmd;15 deleteAutoScaleVmProfile=org.apache.cloudstack.api.user.autoscale.command.DeleteAutoScaleVmProfileCmd;15 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dd5a36fc/server/src/com/cloud/network/as/AutoScaleManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 7917922..5673c37 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -37,7 +37,7 @@ import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScalePolicyCmd import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmGroupCmd; import org.apache.cloudstack.api.user.autoscale.command.CreateAutoScaleVmProfileCmd; import org.apache.cloudstack.api.user.autoscale.command.CreateConditionCmd; -import com.cloud.api.commands.CreateCounterCmd; +import org.apache.cloudstack.api.admin.autoscale.command.CreateCounterCmd; import org.apache.cloudstack.api.user.vm.command.DeployVMCmd; import org.apache.cloudstack.api.user.autoscale.command.ListAutoScalePoliciesCmd; import org.apache.cloudstack.api.user.autoscale.command.ListAutoScaleVmGroupsCmd;
