You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/06 00:32:08 UTC

[2/3] api_refactor: router apis for admin pkg

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/api/src/org/apache/cloudstack/api/admin/router/command/StopRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/router/command/StopRouterCmd.java b/api/src/org/apache/cloudstack/api/admin/router/command/StopRouterCmd.java
new file mode 100644
index 0000000..593b4c6
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/router/command/StopRouterCmd.java
@@ -0,0 +1,116 @@
+// 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.router.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.DomainRouterResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description = "Stops a router.", responseObject = DomainRouterResponse.class)
+public class StopRouterCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName());
+    private static final String s_name = "stoprouterresponse";
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the router")
+    private Long id;
+
+    @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force stop the VM. The caller knows the VM is stopped.")
+    private Boolean forced;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
+        if (router != null) {
+            return router.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_ROUTER_STOP;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "stopping router: " + getId();
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.DomainRouter;
+    }
+
+    @Override
+    public Long getInstanceId() {
+        return getId();
+    }
+
+    public boolean isForced() {
+        return (forced != null) ? forced : false;
+    }
+
+    @Override
+    public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
+        UserContext.current().setEventDetails("Router Id: "+getId());
+        VirtualRouter result = _routerService.stopRouter(getId(), isForced());
+        if (result != null) {
+            DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to stop router");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/api/src/org/apache/cloudstack/api/admin/router/command/UpgradeRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/router/command/UpgradeRouterCmd.java b/api/src/org/apache/cloudstack/api/admin/router/command/UpgradeRouterCmd.java
new file mode 100644
index 0000000..11633bd
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/router/command/UpgradeRouterCmd.java
@@ -0,0 +1,90 @@
+// 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.router.command;
+
+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 org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.DomainRouterResponse;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.user.Account;
+
+@Implementation(description="Upgrades domain router to a new service offering", responseObject=DomainRouterResponse.class)
+public class UpgradeRouterCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(UpgradeRouterCmd.class.getName());
+    private static final String s_name = "changeserviceforrouterresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the router")
+    private Long id;
+
+    @IdentityMapper(entityTableName="disk_offering")
+    @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, required=true, description="the service offering ID to apply to the domain router")
+    private Long serviceOfferingId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public Long getServiceOfferingId() {
+        return serviceOfferingId;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+         return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
+        if (router != null) {
+            return router.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public void execute(){
+        VirtualRouter router = _routerService.upgradeRouter(this);
+        if (router != null){
+            DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(router);
+            routerResponse.setResponseName(getCommandName());
+            this.setResponseObject(routerResponse);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade router");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/api/src/org/apache/cloudstack/api/user/datacenter/command/ListHypervisorsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/datacenter/command/ListHypervisorsCmd.java b/api/src/org/apache/cloudstack/api/user/datacenter/command/ListHypervisorsCmd.java
index 4b5a60f..ac7abab 100644
--- a/api/src/org/apache/cloudstack/api/user/datacenter/command/ListHypervisorsCmd.java
+++ b/api/src/org/apache/cloudstack/api/user/datacenter/command/ListHypervisorsCmd.java
@@ -19,7 +19,7 @@ package org.apache.cloudstack.api.user.datacenter.command;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.cloud.api.commands.UpgradeRouterCmd;
+import org.apache.cloudstack.api.admin.router.command.UpgradeRouterCmd;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.ApiConstants;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index ca7321c..441271b 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -176,14 +176,15 @@ updateAutoScaleVmProfile=org.apache.cloudstack.api.user.autoscale.command.Update
 updateAutoScaleVmGroup=org.apache.cloudstack.api.user.autoscale.command.UpdateAutoScaleVmGroupCmd;15
 
 #### router commands
-startRouter=com.cloud.api.commands.StartRouterCmd;7
-rebootRouter=com.cloud.api.commands.RebootRouterCmd;7
-stopRouter=com.cloud.api.commands.StopRouterCmd;7
-destroyRouter=com.cloud.api.commands.DestroyRouterCmd;7
-changeServiceForRouter=com.cloud.api.commands.UpgradeRouterCmd;7
-listRouters=com.cloud.api.commands.ListRoutersCmd;7
-listVirtualRouterElements=com.cloud.api.commands.ListVirtualRouterElementsCmd;7
-configureVirtualRouterElement=com.cloud.api.commands.ConfigureVirtualRouterElementCmd;7
+startRouter=org.apache.cloudstack.api.admin.router.command.StartRouterCmd;7
+rebootRouter=org.apache.cloudstack.api.admin.router.command.RebootRouterCmd;7
+stopRouter=org.apache.cloudstack.api.admin.router.command.StopRouterCmd;7
+destroyRouter=org.apache.cloudstack.api.admin.router.command.DestroyRouterCmd;7
+changeServiceForRouter=org.apache.cloudstack.api.admin.router.command.UpgradeRouterCmd;7
+listRouters=org.apache.cloudstack.api.admin.router.command.ListRoutersCmd;7
+listVirtualRouterElements=org.apache.cloudstack.api.admin.router.command.ListVirtualRouterElementsCmd;7
+configureVirtualRouterElement=org.apache.cloudstack.api.admin.router.command.ConfigureVirtualRouterElementCmd;7
+createVirtualRouterElement=org.apache.cloudstack.api.admin.router.command.CreateVirtualRouterElementCmd;7
 
 #### system vm commands
 startSystemVm=com.cloud.api.commands.StartSystemVMCmd;1

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index 4ff1082..5339b3f 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -24,10 +24,10 @@ import java.util.Set;
 
 import javax.ejb.Local;
 
+import org.apache.cloudstack.api.admin.router.command.ConfigureVirtualRouterElementCmd;
+import org.apache.cloudstack.api.admin.router.command.ListVirtualRouterElementsCmd;
 import org.apache.log4j.Logger;
 
-import com.cloud.api.commands.ConfigureVirtualRouterElementCmd;
-import com.cloud.api.commands.ListVirtualRouterElementsCmd;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.DataCenter;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 5d0892a..d06c326 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit;
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.api.admin.router.command.UpgradeRouterCmd;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -80,7 +81,6 @@ import com.cloud.agent.api.to.StaticNatRuleTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.alert.AlertManager;
-import com.cloud.api.commands.UpgradeRouterCmd;
 import com.cloud.cluster.ManagementServerHostVO;
 import com.cloud.cluster.ManagementServerNode;
 import com.cloud.cluster.dao.ManagementServerHostDao;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c59de6cb/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 f6e9207..7a8d562 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -42,6 +42,7 @@ import java.util.concurrent.TimeUnit;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
+import org.apache.cloudstack.api.admin.router.command.ListRoutersCmd;
 import org.apache.cloudstack.api.user.resource.command.ListCapabilitiesCmd;
 import org.apache.cloudstack.api.user.guest.command.ListGuestOsCategoriesCmd;
 import org.apache.cloudstack.api.user.guest.command.ListGuestOsCmd;
@@ -82,7 +83,6 @@ import org.apache.cloudstack.api.user.event.command.ListEventsCmd;
 import com.cloud.api.commands.ListHostsCmd;
 import com.cloud.api.commands.ListPodsByCmd;
 import org.apache.cloudstack.api.user.address.command.ListPublicIpAddressesCmd;
-import com.cloud.api.commands.ListRoutersCmd;
 import org.apache.cloudstack.api.user.ssh.command.ListSSHKeyPairsCmd;
 import com.cloud.api.commands.ListStoragePoolsCmd;
 import com.cloud.api.commands.ListSystemVMsCmd;