You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/02/07 22:46:10 UTC

[01/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Updated Branches:
  refs/heads/rbac c440d9046 -> 3b58a45e0


ExternalUUID control support for Firewall and Egress Firewall rules


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/aaa20947
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/aaa20947
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/aaa20947

Branch: refs/heads/rbac
Commit: aaa20947a9b200f9a4abdb0977b5648c92931f68
Parents: 039b1c1
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Feb 4 16:26:53 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Tue Feb 4 17:06:04 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java         |   1 +
 .../cloud/network/firewall/FirewallService.java |   2 +
 .../firewall/UpdateEgressFirewallRuleCmd.java   | 113 ++++++++++++++++++
 .../user/firewall/UpdateFirewallRuleCmd.java    | 114 +++++++++++++++++++
 client/tomcatconf/commands.properties.in        |   2 +
 .../network/firewall/FirewallManagerImpl.java   |  31 ++++-
 .../com/cloud/server/ManagementServerImpl.java  |   4 +
 .../cloud/network/MockFirewallManagerImpl.java  |   6 +
 8 files changed, 270 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index e88f010..fdbc21f 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -112,6 +112,7 @@ public class EventTypes {
     public static final String EVENT_NETWORK_UPDATE = "NETWORK.UPDATE";
     public static final String EVENT_FIREWALL_OPEN = "FIREWALL.OPEN";
     public static final String EVENT_FIREWALL_CLOSE = "FIREWALL.CLOSE";
+    public static final String EVENT_FIREWALL_UPDATE = "FIREWALL.UPDATE";
 
     //NIC Events
     public static final String EVENT_NIC_CREATE = "NIC.CREATE";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/api/src/com/cloud/network/firewall/FirewallService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/firewall/FirewallService.java b/api/src/com/cloud/network/firewall/FirewallService.java
index 917bda3..0e4f495 100644
--- a/api/src/com/cloud/network/firewall/FirewallService.java
+++ b/api/src/com/cloud/network/firewall/FirewallService.java
@@ -50,4 +50,6 @@ public interface FirewallService {
 
     boolean revokeRelatedFirewallRule(long ruleId, boolean apply);
 
+    FirewallRule updateFirewallRule(long ruleId, String customId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java
new file mode 100644
index 0000000..690afe5
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.package org.apache.cloudstack.api.command.user.firewall;
+
+package org.apache.cloudstack.api.command.user.firewall;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.FirewallResponse;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.TrafficType;
+
+@APICommand(name = "updateEgressFirewallRule", description = "Updates egress firewall rule ", responseObject = FirewallResponse.class, since = "4.4")
+public class UpdateEgressFirewallRuleCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateEgressFirewallRuleCmd.class.getName());
+
+    private static final String s_name = "updateegressfirewallruleresponse";
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the egress firewall rule")
+    private Long id;
+
+    // unexposed parameter needed for events logging
+    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
+    private Long ownerId;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException {
+        CallContext.current().setEventDetails("Rule Id: " + id);
+        FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId());
+
+        FirewallResponse fwResponse = new FirewallResponse();
+        if (rule != null) {
+            fwResponse = _responseGenerator.createFirewallResponse(rule);
+            setResponseObject(fwResponse);
+        }
+        fwResponse.setResponseName(getCommandName());
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
+        }
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_FIREWALL_UPDATE;
+
+    }
+
+    @Override
+    public String getEventDescription() {
+        return ("Updating egress firewall rule id=" + id);
+
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        if (ownerId == null) {
+            FirewallRule rule = _entityMgr.findById(FirewallRule.class, id);
+            if (rule == null || rule.getTrafficType() != TrafficType.Egress) {
+                throw new InvalidParameterValueException("Unable to find egress firewall rule by id");
+            } else {
+                ownerId = _entityMgr.findById(FirewallRule.class, id).getAccountId();
+            }
+        }
+        return ownerId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java
new file mode 100644
index 0000000..3fa3b9e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java
@@ -0,0 +1,114 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.package org.apache.cloudstack.api.command.user.firewall;
+
+package org.apache.cloudstack.api.command.user.firewall;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.FirewallResponse;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.TrafficType;
+
+@APICommand(name = "updateFirewallRule", description = "Updates firewall rule ", responseObject = FirewallResponse.class, since = "4.4")
+public class UpdateFirewallRuleCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateFirewallRuleCmd.class.getName());
+
+    private static final String s_name = "updatefirewallruleresponse";
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the firewall rule")
+    private Long id;
+
+    // unexposed parameter needed for events logging
+    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
+    private Long ownerId;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException {
+        CallContext.current().setEventDetails("Rule Id: " + id);
+        FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId());
+
+        FirewallResponse fwResponse = new FirewallResponse();
+        if (rule != null) {
+            fwResponse = _responseGenerator.createFirewallResponse(rule);
+            setResponseObject(fwResponse);
+        }
+        fwResponse.setResponseName(getCommandName());
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
+        }
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_FIREWALL_UPDATE;
+
+    }
+
+    @Override
+    public String getEventDescription() {
+        return ("Updating firewall rule id=" + id);
+
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        if (ownerId == null) {
+            FirewallRule rule = _entityMgr.findById(FirewallRule.class, id);
+            if (rule == null || rule.getTrafficType() != TrafficType.Ingress) {
+                throw new InvalidParameterValueException("Unable to find firewall rule by id");
+            } else {
+                ownerId = _entityMgr.findById(FirewallRule.class, id).getAccountId();
+            }
+        }
+        return ownerId;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index aecc912..27ed6cf 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -401,11 +401,13 @@ deleteProjectInvitation=15
 createFirewallRule=15
 deleteFirewallRule=15
 listFirewallRules=15
+updateFirewallRule=15
 
 ####
 createEgressFirewallRule=15
 deleteEgressFirewallRule=15
 listEgressFirewallRules=15
+updateEgressFirewallRule=15
 
 #### hypervisor capabilities commands
 updateHypervisorCapabilities=1

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index 448abe3..593c0b5 100644
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@ -27,13 +27,12 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.Config;
 import com.cloud.domain.dao.DomainDao;
@@ -717,6 +716,32 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
     }
 
     @Override
+    @ActionEvent(eventType = EventTypes.EVENT_FIREWALL_UPDATE, eventDescription = "updating firewall rule", async = true)
+    public FirewallRule updateFirewallRule(long ruleId, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+        return updateFirewallRule(ruleId, customId, caller);
+    }
+
+    protected FirewallRule updateFirewallRule(long ruleId, String customId, Account caller) {
+        FirewallRuleVO rule = _firewallDao.findById(ruleId);
+        if (rule == null || rule.getPurpose() != Purpose.Firewall) {
+            throw new InvalidParameterValueException("Unable to find " + ruleId + " having purpose " + Purpose.Firewall);
+        }
+
+        if (rule.getType() == FirewallRuleType.System && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            throw new InvalidParameterValueException("Only root admin can update the system wide firewall rule");
+        }
+
+        _accountMgr.checkAccess(caller, null, true, rule);
+
+        if (customId != null) {
+            rule.setUuid(customId);
+            _firewallDao.update(ruleId, rule);
+        }
+        return _firewallDao.findById(ruleId);
+    }
+
+    @Override
     @DB
     public void revokeRule(final FirewallRuleVO rule, Account caller, long userId, final boolean needUsageEvent) {
         if (caller != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/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 449e879..9dc9dda 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -255,6 +255,8 @@ import org.apache.cloudstack.api.command.user.firewall.DeletePortForwardingRuleC
 import org.apache.cloudstack.api.command.user.firewall.ListEgressFirewallRulesCmd;
 import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
 import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
+import org.apache.cloudstack.api.command.user.firewall.UpdateEgressFirewallRuleCmd;
+import org.apache.cloudstack.api.command.user.firewall.UpdateFirewallRuleCmd;
 import org.apache.cloudstack.api.command.user.firewall.UpdatePortForwardingRuleCmd;
 import org.apache.cloudstack.api.command.user.guest.ListGuestOsCategoriesCmd;
 import org.apache.cloudstack.api.command.user.guest.ListGuestOsCmd;
@@ -2861,6 +2863,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(ListOvsElementsCmd.class);
         cmdList.add(ConfigureOvsElementCmd.class);
         cmdList.add(GetVMUserDataCmd.class);
+        cmdList.add(UpdateEgressFirewallRuleCmd.class);
+        cmdList.add(UpdateFirewallRuleCmd.class);
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa20947/server/test/com/cloud/network/MockFirewallManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockFirewallManagerImpl.java b/server/test/com/cloud/network/MockFirewallManagerImpl.java
index 3fbbcdf..b306976 100644
--- a/server/test/com/cloud/network/MockFirewallManagerImpl.java
+++ b/server/test/com/cloud/network/MockFirewallManagerImpl.java
@@ -184,4 +184,10 @@ public class MockFirewallManagerImpl extends ManagerBase implements FirewallMana
         return null;
     }
 
+    @Override
+    public FirewallRule updateFirewallRule(long ruleId, String customId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }


[30/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
External UUID control support for PublicIpAddress/RemoteAccessVpn/PortForwardingRule/S2SVpnGateway/S2SVpnConnection


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4305d817
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4305d817
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4305d817

Branch: refs/heads/rbac
Commit: 4305d817ba035a15208b859280147a37b07b1c52
Parents: 75757e9
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Feb 5 14:17:33 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Feb 5 15:56:40 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java         |   4 +
 api/src/com/cloud/network/NetworkService.java   |   2 +
 .../com/cloud/network/rules/RulesService.java   |   2 +
 .../network/vpn/RemoteAccessVpnService.java     |   5 +
 .../cloud/network/vpn/Site2SiteVpnService.java  |   4 +
 .../command/user/address/UpdateIPAddrCmd.java   | 122 +++++++++++++++++++
 .../firewall/UpdatePortForwardingRuleCmd.java   |  32 +++--
 .../UpdateApplicationLoadBalancerCmd.java       |   3 +-
 .../loadbalancer/UpdateLoadBalancerRuleCmd.java |   3 +-
 .../user/vpn/UpdateRemoteAccessVpnCmd.java      | 102 ++++++++++++++++
 .../user/vpn/UpdateVpnConnectionCmd.java        |  90 ++++++++++++++
 .../command/user/vpn/UpdateVpnGatewayCmd.java   |  89 ++++++++++++++
 .../Site2SiteVpnConnectionResponse.java         |   5 +-
 client/tomcatconf/commands.properties.in        |   5 +
 .../cloud/network/dao/RemoteAccessVpnVO.java    |   4 +
 .../network/dao/Site2SiteVpnConnectionVO.java   |   4 +
 .../network/dao/Site2SiteVpnGatewayVO.java      |   4 +
 .../com/cloud/network/NetworkServiceImpl.java   |  23 ++++
 .../cloud/network/rules/RulesManagerImpl.java   |  20 ++-
 .../network/vpn/RemoteAccessVpnManagerImpl.java |  26 +++-
 .../network/vpn/Site2SiteVpnManagerImpl.java    |  42 ++++++-
 .../com/cloud/server/ManagementServerImpl.java  |  13 +-
 .../com/cloud/vpc/MockNetworkManagerImpl.java   |  10 +-
 .../cloud/vpc/MockSite2SiteVpnManagerImpl.java  |  15 ++-
 24 files changed, 602 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index 51f8f1b..7dd8772 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -102,6 +102,7 @@ public class EventTypes {
     // Network Events
     public static final String EVENT_NET_IP_ASSIGN = "NET.IPASSIGN";
     public static final String EVENT_NET_IP_RELEASE = "NET.IPRELEASE";
+    public static final String EVENT_NET_IP_UPDATE = "NET.IPUPDATE";
     public static final String EVENT_PORTABLE_IP_ASSIGN = "PORTABLE.IPASSIGN";
     public static final String EVENT_PORTABLE_IP_RELEASE = "PORTABLE.IPRELEASE";
     public static final String EVENT_NET_RULE_ADD = "NET.RULEADD";
@@ -286,16 +287,19 @@ public class EventTypes {
     // VPN
     public static final String EVENT_REMOTE_ACCESS_VPN_CREATE = "VPN.REMOTE.ACCESS.CREATE";
     public static final String EVENT_REMOTE_ACCESS_VPN_DESTROY = "VPN.REMOTE.ACCESS.DESTROY";
+    public static final String EVENT_REMOTE_ACCESS_VPN_UPDATE = "VPN.REMOTE.ACCESS.UPDATE";
     public static final String EVENT_VPN_USER_ADD = "VPN.USER.ADD";
     public static final String EVENT_VPN_USER_REMOVE = "VPN.USER.REMOVE";
     public static final String EVENT_S2S_VPN_GATEWAY_CREATE = "VPN.S2S.VPN.GATEWAY.CREATE";
     public static final String EVENT_S2S_VPN_GATEWAY_DELETE = "VPN.S2S.VPN.GATEWAY.DELETE";
+    public static final String EVENT_S2S_VPN_GATEWAY_UPDATE = "VPN.S2S.VPN.GATEWAY.UPDATE";
     public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE = "VPN.S2S.CUSTOMER.GATEWAY.CREATE";
     public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE = "VPN.S2S.CUSTOMER.GATEWAY.DELETE";
     public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE = "VPN.S2S.CUSTOMER.GATEWAY.UPDATE";
     public static final String EVENT_S2S_VPN_CONNECTION_CREATE = "VPN.S2S.CONNECTION.CREATE";
     public static final String EVENT_S2S_VPN_CONNECTION_DELETE = "VPN.S2S.CONNECTION.DELETE";
     public static final String EVENT_S2S_VPN_CONNECTION_RESET = "VPN.S2S.CONNECTION.RESET";
+    public static final String EVENT_S2S_VPN_CONNECTION_UPDATE = "VPN.S2S.CONNECTION.UPDATE";
 
     // Network
     public static final String EVENT_NETWORK_RESTART = "NETWORK.RESTART";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/com/cloud/network/NetworkService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java
index d7d8546..072a27d 100755
--- a/api/src/com/cloud/network/NetworkService.java
+++ b/api/src/com/cloud/network/NetworkService.java
@@ -176,4 +176,6 @@ public interface NetworkService {
     List<? extends Nic> listNics(ListNicsCmd listNicsCmd);
 
     Map<Network.Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service);
+
+    IpAddress updateIP(Long id, String customId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/com/cloud/network/rules/RulesService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java
index 39329d5..1bd9cfe 100644
--- a/api/src/com/cloud/network/rules/RulesService.java
+++ b/api/src/com/cloud/network/rules/RulesService.java
@@ -80,4 +80,6 @@ public interface RulesService {
 
     boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException;
 
+    PortForwardingRule updatePortForwardingRule(long id, String customId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java
index ac9649b..1183211 100644
--- a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java
+++ b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java
@@ -52,4 +52,9 @@ public interface RemoteAccessVpnService {
     List<? extends RemoteAccessVpn> listRemoteAccessVpns(long networkId);
 
     RemoteAccessVpn getRemoteAccessVpn(long vpnAddrId);
+
+    RemoteAccessVpn getRemoteAccessVpnById(long vpnId);
+
+    RemoteAccessVpn updateRemoteAccessVpn(long id, String customId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/com/cloud/network/vpn/Site2SiteVpnService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java
index bfc5e25..7b76b3a 100644
--- a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java
+++ b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java
@@ -63,4 +63,8 @@ public interface Site2SiteVpnService {
     Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnections(ListVpnConnectionsCmd listVpnConnectionsCmd);
 
     Site2SiteCustomerGateway updateCustomerGateway(UpdateVpnCustomerGatewayCmd updateVpnCustomerGatewayCmd);
+
+    Site2SiteVpnConnection updateVpnConnection(long id, String customId);
+
+    Site2SiteVpnGateway updateVpnGateway(Long id, String customId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
new file mode 100644
index 0000000..b45bf94
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
@@ -0,0 +1,122 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.address;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+import com.cloud.user.Account;
+
+@APICommand(name = "updatePublicIpAddress", description = "Updates an ip address", responseObject = IPAddressResponse.class)
+public class UpdateIPAddrCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateIPAddrCmd.class.getName());
+    private static final String s_name = "updateipaddressresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IPAddressResponse.class, required = true, description = "the id of the public ip address"
+            + " to update")
+    private Long id;
+    // unexposed parameter needed for events logging
+    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
+    private Long ownerId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_NET_IP_UPDATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return ("Updating ip address with id=" + id);
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        if (ownerId == null) {
+            IpAddress ip = getIpAddress(id);
+            if (ip == null) {
+                throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+            }
+            ownerId = ip.getAccountId();
+        }
+
+        if (ownerId == null) {
+            return Account.ACCOUNT_ID_SYSTEM;
+        }
+        return ownerId;
+    }
+
+    private IpAddress getIpAddress(long id) {
+        IpAddress ip = _entityMgr.findById(IpAddress.class, id);
+
+        if (ip == null) {
+            throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+        } else {
+            return ip;
+        }
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), IpAddress.class);
+        }
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
+            NetworkRuleConflictException {
+
+        IpAddress result = _networkService.updateIP(getId(), this.getCustomId());
+        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
+        ipResponse.setResponseName(getCommandName());
+        setResponseObject(ipResponse);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
index d7e380f..a7bb7e3 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
@@ -16,52 +16,54 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.firewall;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.FirewallRuleResponse;
 import org.apache.cloudstack.api.response.IPAddressResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.network.IpAddress;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.PortForwardingRule;
 import com.cloud.user.Account;
 
 @APICommand(name = "updatePortForwardingRule",
             responseObject = FirewallRuleResponse.class,
-            description = "Updates a port forwarding rule.  Only the private port and the virtual machine can be updated.")
-public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
+ description = "Updates a port forwarding rule")
+public class UpdatePortForwardingRuleCmd extends BaseAsyncCustomIdCmd {
     public static final Logger s_logger = Logger.getLogger(UpdatePortForwardingRuleCmd.class.getName());
     private static final String s_name = "updateportforwardingruleresponse";
 
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the port forwarding rule")
+    private Long id;
 
     @Parameter(name = ApiConstants.PRIVATE_IP, type = CommandType.STRING, description = "the private IP address of the port forwarding rule")
     private String privateIp;
 
-    @Parameter(name = ApiConstants.PRIVATE_PORT, type = CommandType.STRING, required = true, description = "the private port of the port forwarding rule")
+    @Parameter(name = ApiConstants.PRIVATE_PORT, type = CommandType.STRING, description = "the private port of the port forwarding rule")
     private String privatePort;
 
     @Parameter(name = ApiConstants.PROTOCOL,
                type = CommandType.STRING,
-               required = true,
                description = "the protocol for the port fowarding rule. Valid values are TCP or UDP.")
     private String protocol;
 
     @Parameter(name = ApiConstants.IP_ADDRESS_ID,
                type = CommandType.UUID,
                entityType = IPAddressResponse.class,
-               required = true,
                description = "the IP address id of the port forwarding rule")
     private Long publicIpId;
 
-    @Parameter(name = ApiConstants.PUBLIC_PORT, type = CommandType.STRING, required = true, description = "the public port of the port forwarding rule")
+    @Parameter(name = ApiConstants.PUBLIC_PORT, type = CommandType.STRING, description = "the public port of the port forwarding rule")
     private String publicPort;
 
     @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
@@ -129,7 +131,21 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
     }
 
     @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
+        }
+    }
+
+    @Override
     public void execute() {
+        PortForwardingRule rule = _rulesService.updatePortForwardingRule(id, this.getCustomId());
+        FirewallRuleResponse fwResponse = new FirewallRuleResponse();
+        if (rule != null) {
+            fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
+            setResponseObject(fwResponse);
+        }
+        fwResponse.setResponseName(getCommandName());
 //FIXME:        PortForwardingRule result = _mgr.updatePortForwardingRule(this);
 //        if (result != null) {
 //            FirewallRuleResponse response = _responseGenerator.createFirewallRuleResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
index 5f89692..4a82ce1 100644
--- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
@@ -28,6 +28,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.rules.FirewallRule;
 
 @APICommand(name = "updateLoadBalancer", description = "Updates a Load Balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0")
 public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd {
@@ -89,7 +90,7 @@ public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd {
     @Override
     public void checkUuid() {
         if (this.getCustomId() != null) {
-            _uuidMgr.checkUuid(this.getCustomId(), ApplicationLoadBalancerRule.class);
+            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
index f408756..3a9a03c 100644
--- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
@@ -30,6 +30,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.LoadBalancer;
 import com.cloud.user.Account;
 
@@ -136,7 +137,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
     @Override
     public void checkUuid() {
         if (this.getCustomId() != null) {
-            _uuidMgr.checkUuid(this.getCustomId(), LoadBalancer.class);
+            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java
new file mode 100644
index 0000000..e275faf
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java
@@ -0,0 +1,102 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.RemoteAccessVpn;
+
+@APICommand(name = "updateRemoteAccessVpn", description = "Updates remote access vpn", responseObject = RemoteAccessVpnResponse.class, since = "4.4")
+public class UpdateRemoteAccessVpnCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateRemoteAccessVpnCmd.class.getName());
+
+    private static final String s_name = "updateremoteaccessvpnresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = true, entityType = RemoteAccessVpnResponse.class, description = "id of the remote access vpn")
+    private Long id;
+
+    // unexposed parameter needed for events logging
+    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
+    private Long ownerId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        if (ownerId == null) {
+            RemoteAccessVpn vpnEntity = _ravService.getRemoteAccessVpnById(id);
+            if (vpnEntity != null)
+                return vpnEntity.getAccountId();
+
+            throw new InvalidParameterValueException("The specified id is invalid");
+        }
+        return ownerId;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Updating remote access vpn id=" + id;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_REMOTE_ACCESS_VPN_UPDATE;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() {
+        RemoteAccessVpn result = _ravService.updateRemoteAccessVpn(id, this.getCustomId());
+        RemoteAccessVpnResponse response = _responseGenerator.createRemoteAccessVpnResponse(result);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), RemoteAccessVpn.class);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java
new file mode 100644
index 0000000..5fee7a2
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.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.command.user.vpn;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.user.Account;
+
+@APICommand(name = "updateVpnConnection", description = "Updates site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, since = "4.4")
+public class UpdateVpnConnectionCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateVpnConnectionCmd.class.getName());
+
+    private static final String s_name = "updatevpnconnectionresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = Site2SiteVpnConnectionResponse.class, required = true, description = "id of vpn connection")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public Long getId() {
+        return id;
+    }
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Site2SiteVpnConnection conn = _entityMgr.findById(Site2SiteVpnConnection.class, getId());
+        if (conn != null) {
+            return conn.getAccountId();
+        }
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Updating site-to-site VPN connection id= " + id;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_S2S_VPN_CONNECTION_UPDATE;
+    }
+
+    @Override
+    public void execute() {
+        Site2SiteVpnConnection result = _s2sVpnService.updateVpnConnection(id, this.getCustomId());
+        Site2SiteVpnConnectionResponse response = _responseGenerator.createSite2SiteVpnConnectionResponse(result);
+        response.setResponseName(getCommandName());
+        setResponseObject(response);
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), Site2SiteVpnConnection.class);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java
new file mode 100644
index 0000000..30c56b4
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.user.Account;
+
+@APICommand(name = "updateVpnGateway", description = "Updates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, since = "4.4")
+public class UpdateVpnGatewayCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateVpnGatewayCmd.class.getName());
+
+    private static final String s_name = "updatevpngatewayresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = Site2SiteVpnGatewayResponse.class, required = true, description = "id of customer gateway")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public Long getId() {
+        return id;
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Site2SiteVpnGateway gw = _entityMgr.findById(Site2SiteVpnGateway.class, getId());
+        if (gw != null) {
+            return gw.getAccountId();
+        }
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Update site-to-site VPN gateway id= " + id;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_S2S_VPN_GATEWAY_UPDATE;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public void execute() {
+        Site2SiteVpnGateway result = _s2sVpnService.updateVpnGateway(id, this.getCustomId());
+        Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result);
+        response.setResponseName(getCommandName());
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), Site2SiteVpnGateway.class);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java b/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java
index 423b6cd..f025b52 100644
--- a/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java
@@ -18,20 +18,19 @@ package org.apache.cloudstack.api.response;
 
 import java.util.Date;
 
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.EntityReference;
 
 import com.cloud.network.Site2SiteVpnConnection;
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 @EntityReference(value = Site2SiteVpnConnection.class)
 @SuppressWarnings("unused")
 public class Site2SiteVpnConnectionResponse extends BaseResponse implements ControlledEntityResponse {
     @SerializedName(ApiConstants.ID)
-    @Param(description = "the vpn gateway ID")
+    @Param(description = "the connection ID")
     private String id;
 
     @SerializedName(ApiConstants.S2S_VPN_GATEWAY_ID)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 2992eea..879c58d 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -137,6 +137,7 @@ listDedicatedGuestVlanRanges=1
 associateIpAddress=15
 disassociateIpAddress=15
 listPublicIpAddresses=15
+updatePublicIpAddress=15
 
 #### firewall commands
 listPortForwardingRules=15
@@ -349,6 +350,8 @@ listHypervisors=15
 createRemoteAccessVpn=15
 deleteRemoteAccessVpn=15
 listRemoteAccessVpns=15
+updateRemoteAccessVpn=15
+
 
 addVpnUser=15
 removeVpnUser=15
@@ -501,6 +504,8 @@ resetVpnConnection=15
 listVpnCustomerGateways=15
 listVpnGateways=15
 listVpnConnections=15
+updateVpnConnection=15
+updateVpnGateway=15
 
 #### router commands
 createVirtualRouterElement=7

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
index 54ae9b2..c892949 100644
--- a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
+++ b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
@@ -148,4 +148,8 @@ public class RemoteAccessVpnVO implements RemoteAccessVpn {
     public Long getVpcId() {
         return vpcId;
     }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
index 96a4c2d..7f1d0aa 100644
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
@@ -155,4 +155,8 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection, Interna
     public void setPassive(boolean passive) {
         this.passive = passive;
     }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
index 3a16bcd..5e8c6b6 100644
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
@@ -112,4 +112,8 @@ public class Site2SiteVpnGatewayVO implements Site2SiteVpnGateway {
     public long getAccountId() {
         return accountId;
     }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index c786426..bcadd69 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -4034,4 +4034,27 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
         this._networkGurus = networkGurus;
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_NET_IP_UPDATE, eventDescription = "updating public ip address", async = true)
+    public IpAddress updateIP(Long id, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+        IPAddressVO ipVO = _ipAddressDao.findById(id);
+        if (ipVO == null) {
+            throw new InvalidParameterValueException("Unable to find ip address by id");
+        }
+
+        // verify permissions
+        if (ipVO.getAllocatedToAccountId() != null) {
+            _accountMgr.checkAccess(caller, null, true, ipVO);
+        } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            throw new PermissionDeniedException("Only Root admin can update non-allocated ip addresses");
+        }
+
+        if (customId != null) {
+            ipVO.setUuid(customId);
+        }
+        _ipAddressDao.update(id, ipVO);
+        return _ipAddressDao.findById(id);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index 69be58f..2fa72a7 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -25,11 +25,10 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
+import org.apache.log4j.Logger;
 
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.domain.dao.DomainDao;
@@ -1484,4 +1483,21 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
         }
         return result;
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_NET_RULE_MODIFY, eventDescription = "updating forwarding rule", async = true)
+    public PortForwardingRule updatePortForwardingRule(long id, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+        PortForwardingRuleVO rule = _portForwardingDao.findById(id);
+        if (rule == null) {
+            throw new InvalidParameterValueException("Unable to find " + id);
+        }
+        _accountMgr.checkAccess(caller, null, true, rule);
+
+        if (customId != null) {
+            rule.setUuid(customId);
+        }
+        _portForwardingDao.update(id, rule);
+        return _portForwardingDao.findById(id);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
index ef4cccd..0b33ae3 100755
--- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
@@ -25,18 +25,18 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.command.user.vpn.ListRemoteAccessVpnsCmd;
 import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.log4j.Logger;
 
 import com.cloud.configuration.Config;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
+import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.event.dao.UsageEventDao;
@@ -696,6 +696,11 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
         return _remoteAccessVpnDao.findByPublicIpAddress(vpnAddrId);
     }
 
+    @Override
+    public RemoteAccessVpn getRemoteAccessVpnById(long vpnId) {
+        return _remoteAccessVpnDao.findById(vpnId);
+    }
+
     public List<RemoteAccessVPNServiceProvider> getRemoteAccessVPNServiceProviders() {
         List<RemoteAccessVPNServiceProvider> result = new ArrayList<RemoteAccessVPNServiceProvider>();
         for (Iterator<RemoteAccessVPNServiceProvider> e = _vpnServiceProviders.iterator(); e.hasNext();) {
@@ -723,4 +728,21 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
         this._vpnServiceProviders = vpnServiceProviders;
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_REMOTE_ACCESS_VPN_UPDATE, eventDescription = "updating remote access vpn", async = true)
+    public RemoteAccessVpn updateRemoteAccessVpn(long id, String customId) {
+        final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findById(id);
+        if (vpn == null) {
+            throw new InvalidParameterValueException("Can't find remote access vpn by id " + id);
+        }
+
+        _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, vpn);
+        if (customId != null) {
+            vpn.setUuid(customId);
+        }
+
+        _remoteAccessVpnDao.update(vpn.getId(), vpn);
+        return _remoteAccessVpnDao.findById(id);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index d068ca0..2f6ad6c 100644
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
@@ -24,9 +24,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnConnectionCmd;
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnCustomerGatewayCmd;
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnGatewayCmd;
@@ -40,6 +37,8 @@ import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
 import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.Config;
 import com.cloud.event.ActionEvent;
@@ -783,4 +782,41 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
     public void setS2sProviders(List<Site2SiteVpnServiceProvider> s2sProviders) {
         this._s2sProviders = s2sProviders;
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_UPDATE, eventDescription = "creating s2s vpn gateway", async = true)
+    public Site2SiteVpnConnection updateVpnConnection(long id, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+        Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
+        if (conn == null) {
+            throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id);
+        }
+
+        _accountMgr.checkAccess(caller, null, false, conn);
+        if (customId != null) {
+            conn.setUuid(customId);
+        }
+
+        _vpnConnectionDao.update(id, conn);
+        return _vpnConnectionDao.findById(id);
+    }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_UPDATE, eventDescription = "updating s2s vpn gateway", async = true)
+    public Site2SiteVpnGateway updateVpnGateway(Long id, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+
+        Site2SiteVpnGatewayVO vpnGateway = _vpnGatewayDao.findById(id);
+        if (vpnGateway == null) {
+            throw new InvalidParameterValueException("Fail to find vpn gateway with " + id);
+        }
+
+        _accountMgr.checkAccess(caller, null, false, vpnGateway);
+        if (customId != null) {
+            vpnGateway.setUuid(customId);
+        }
+        _vpnGatewayDao.update(id, vpnGateway);
+        return _vpnGatewayDao.findById(id);
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/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 ad4e760..2a08ddc4 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -40,9 +40,6 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -221,6 +218,7 @@ import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
 import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
 import org.apache.cloudstack.api.command.user.address.DisassociateIPAddrCmd;
 import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
+import org.apache.cloudstack.api.command.user.address.UpdateIPAddrCmd;
 import org.apache.cloudstack.api.command.user.affinitygroup.CreateAffinityGroupCmd;
 import org.apache.cloudstack.api.command.user.affinitygroup.DeleteAffinityGroupCmd;
 import org.apache.cloudstack.api.command.user.affinitygroup.ListAffinityGroupTypesCmd;
@@ -436,7 +434,10 @@ import org.apache.cloudstack.api.command.user.vpn.ListVpnGatewaysCmd;
 import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
 import org.apache.cloudstack.api.command.user.vpn.RemoveVpnUserCmd;
 import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
+import org.apache.cloudstack.api.command.user.vpn.UpdateRemoteAccessVpnCmd;
+import org.apache.cloudstack.api.command.user.vpn.UpdateVpnConnectionCmd;
 import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
+import org.apache.cloudstack.api.command.user.vpn.UpdateVpnGatewayCmd;
 import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
 import org.apache.cloudstack.config.Configuration;
 import org.apache.cloudstack.context.CallContext;
@@ -454,6 +455,8 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.GetVncPortAnswer;
@@ -2857,6 +2860,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(UpdateFirewallRuleCmd.class);
         cmdList.add(UpdateNetworkACLListCmd.class);
         cmdList.add(UpdateApplicationLoadBalancerCmd.class);
+        cmdList.add(UpdateIPAddrCmd.class);
+        cmdList.add(UpdateRemoteAccessVpnCmd.class);
+        cmdList.add(UpdateVpnConnectionCmd.class);
+        cmdList.add(UpdateVpnGatewayCmd.class);
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index 32beb0b..68390f8 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -25,8 +25,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
 import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
@@ -36,6 +34,8 @@ import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
 import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
 import org.apache.cloudstack.api.command.user.vm.ListNicsCmd;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.deploy.DataCenterDeployment;
 import com.cloud.deploy.DeployDestination;
@@ -857,4 +857,10 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches
 
     }
 
+    @Override
+    public IpAddress updateIP(Long id, String customId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4305d817/server/test/com/cloud/vpc/MockSite2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockSite2SiteVpnManagerImpl.java b/server/test/com/cloud/vpc/MockSite2SiteVpnManagerImpl.java
index b02e1a4..3815ed1 100644
--- a/server/test/com/cloud/vpc/MockSite2SiteVpnManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockSite2SiteVpnManagerImpl.java
@@ -22,8 +22,6 @@ import java.util.Map;
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnConnectionCmd;
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnCustomerGatewayCmd;
 import org.apache.cloudstack.api.command.user.vpn.CreateVpnGatewayCmd;
@@ -35,6 +33,7 @@ import org.apache.cloudstack.api.command.user.vpn.ListVpnCustomerGatewaysCmd;
 import org.apache.cloudstack.api.command.user.vpn.ListVpnGatewaysCmd;
 import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
 import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
+import org.springframework.stereotype.Component;
 
 import com.cloud.exception.NetworkRuleConflictException;
 import com.cloud.exception.ResourceUnavailableException;
@@ -259,4 +258,16 @@ public class MockSite2SiteVpnManagerImpl extends ManagerBase implements Site2Sit
 
     }
 
+    @Override
+    public Site2SiteVpnConnection updateVpnConnection(long id, String customId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Site2SiteVpnGateway updateVpnGateway(Long id, String customId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }


[35/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
test: Add test for LibvirtDomainXMLParser

A couple of changes where made to other classes as well to add
some features to allow more extensive testing.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/41c7e22e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/41c7e22e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/41c7e22e

Branch: refs/heads/rbac
Commit: 41c7e22eee87c2be87a910b3f11c5f2fa09441c1
Parents: cecb216
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Wed Feb 5 16:26:17 2014 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Thu Feb 6 14:23:25 2014 +0100

----------------------------------------------------------------------
 .../kvm/resource/LibvirtDomainXMLParser.java    |   4 +-
 .../hypervisor/kvm/resource/LibvirtVMDef.java   |  12 ++
 .../resource/LibvirtDomainXMLParserTest.java    | 184 +++++++++++++++++++
 3 files changed, 198 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41c7e22e/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
index 127f648..9fb63ce 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
@@ -76,7 +76,7 @@ public class LibvirtDomainXMLParser {
                     def.defNetworkBasedDisk(diskPath, host, port, authUserName, poolUuid, diskLabel,
                         DiskDef.diskBus.valueOf(bus.toUpperCase()),
                         DiskDef.diskProtocol.valueOf(protocol.toUpperCase()));
-                    def.setCacheMode(DiskDef.diskCacheMode.valueOf(diskCacheMode));
+                    def.setCacheMode(DiskDef.diskCacheMode.valueOf(diskCacheMode.toUpperCase()));
                 } else {
                     String diskFmtType = getAttrValue("driver", "type", disk);
                     String diskCacheMode = getAttrValue("driver", "cache", disk);
@@ -100,8 +100,8 @@ public class LibvirtDomainXMLParser {
                     } else if (type.equalsIgnoreCase("block")) {
                         def.defBlockBasedDisk(diskDev, diskLabel,
                             DiskDef.diskBus.valueOf(bus.toUpperCase()));
-                        def.setCacheMode(DiskDef.diskCacheMode.valueOf(diskCacheMode));
                     }
+                    def.setCacheMode(DiskDef.diskCacheMode.valueOf(diskCacheMode.toUpperCase()));
                 }
 
                 NodeList iotune = disk.getElementsByTagName("iotune");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41c7e22e/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index 5aeacda..1e90093 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -585,6 +585,10 @@ public class LibvirtVMDef {
             return _diskLabel;
         }
 
+        public diskType getDiskType() {
+            return _diskType;
+        }
+
         public deviceType getDeviceType() {
             return _deviceType;
         }
@@ -597,6 +601,10 @@ public class LibvirtVMDef {
             return _bus;
         }
 
+        public diskFmtType getDiskFormatType() {
+            return _diskFmtType;
+        }
+
         public int getDiskSeq() {
             char suffix = _diskLabel.charAt(_diskLabel.length() - 1);
             return suffix - 'a';
@@ -622,6 +630,10 @@ public class LibvirtVMDef {
             _diskCacheMode = cacheMode;
         }
 
+        public diskCacheMode getCacheMode() {
+            return _diskCacheMode;
+        }
+
         @Override
         public String toString() {
             StringBuilder diskBuilder = new StringBuilder();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41c7e22e/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
new file mode 100644
index 0000000..bbe2f23
--- /dev/null
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
@@ -0,0 +1,184 @@
+/*
+ * 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.hypervisor.kvm.resource;
+
+import junit.framework.TestCase;
+import java.util.List;
+import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
+
+public class LibvirtDomainXMLParserTest extends TestCase {
+
+    public void testDomainXMLParser() {
+        int vncPort = 5900;
+
+        DiskDef.diskBus diskBus = DiskDef.diskBus.VIRTIO;
+        DiskDef.diskType diskType = DiskDef.diskType.FILE;
+        DiskDef.deviceType deviceType = DiskDef.deviceType.DISK;
+        DiskDef.diskFmtType diskFormat = DiskDef.diskFmtType.QCOW2;
+        DiskDef.diskCacheMode diskCache = DiskDef.diskCacheMode.NONE;
+
+        String diskLabel ="vda";
+        String diskPath = "/var/lib/libvirt/images/my-test-image.qcow2";
+
+        String xml = "<domain type='kvm' id='10'>" +
+                     "<name>s-2970-VM</name>" +
+                     "<uuid>4d2c1526-865d-4fc9-a1ac-dbd1801a22d0</uuid>" +
+                     "<description>Debian GNU/Linux 6(64-bit)</description>" +
+                     "<memory unit='KiB'>262144</memory>" +
+                     "<currentMemory unit='KiB'>262144</currentMemory>" +
+                     "<vcpu placement='static'>1</vcpu>" +
+                     "<cputune>" +
+                     "<shares>250</shares>" +
+                     "</cputune>" +
+                     "<resource>" +
+                     "<partition>/machine</partition>" +
+                     "</resource>" +
+                     "<os>" +
+                     "<type arch='x86_64' machine='pc-i440fx-1.5'>hvm</type>" +
+                     "<boot dev='cdrom'/>" +
+                     "<boot dev='hd'/>" +
+                     "</os>" +
+                     "<features>" +
+                     "<acpi/>" +
+                     "<apic/>" +
+                     "<pae/>" +
+                     "</features>" +
+                     "<clock offset='utc'/>" +
+                     "<on_poweroff>destroy</on_poweroff>" +
+                     "<on_reboot>restart</on_reboot>" +
+                     "<on_crash>destroy</on_crash>" +
+                     "<devices>" +
+                     "<emulator>/usr/bin/kvm-spice</emulator>" +
+                     "<disk type='" + diskType.toString() + "' device='" + deviceType.toString() + "'>" +
+                     "<driver name='qemu' type='" + diskFormat.toString() + "' cache='" + diskCache.toString() + "'/>" +
+                     "<source file='" + diskPath + "'/>" +
+                     "<target dev='" + diskLabel + "' bus='" + diskBus.toString() + "'/>" +
+                     "<alias name='virtio-disk0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>" +
+                     "</disk>" +
+                     "<disk type='file' device='cdrom'>" +
+                     "<driver name='qemu' type='raw' cache='none'/>" +
+                     "<source file='/usr/share/cloudstack-common/vms/systemvm.iso'/>" +
+                     "<target dev='hdc' bus='ide'/>" +
+                     "<readonly/>" +
+                     "<alias name='ide0-1-0'/>" +
+                     "<address type='drive' controller='0' bus='1' target='0' unit='0'/>" +
+                     "</disk>" +
+                     "<controller type='usb' index='0'>" +
+                     "<alias name='usb0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>" +
+                     "</controller>" +
+                     "<controller type='pci' index='0' model='pci-root'>" +
+                     "<alias name='pci0'/>" +
+                     "</controller>" +
+                     "<controller type='ide' index='0'>" +
+                     "<alias name='ide0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>" +
+                     "</controller>" +
+                     "<controller type='virtio-serial' index='0'>" +
+                     "<alias name='virtio-serial0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>" +
+                     "</controller>" +
+                     "<interface type='bridge'>" +
+                     "<mac address='0e:00:a9:fe:02:00'/>" +
+                     "<source bridge='cloud0'/>" +
+                     "<target dev='vnet0'/>" +
+                     "<model type='virtio'/>" +
+                     "<alias name='net0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>" +
+                     "</interface>" +
+                     "<interface type='bridge'>" +
+                     "<mac address='06:c5:94:00:05:65'/>" +
+                     "<source bridge='cloudbr1'/>" +
+                     "<target dev='vnet1'/>" +
+                     "<model type='virtio'/>" +
+                     "<alias name='net1'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>" +
+                     "</interface>" +
+                     "<interface type='bridge'>" +
+                     "<mac address='06:c9:f4:00:04:40'/>" +
+                     "<source bridge='cloudbr0'/>" +
+                     "<target dev='vnet2'/>" +
+                     "<model type='virtio'/>" +
+                     "<alias name='net2'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>" +
+                     "</interface>" +
+                     "<interface type='bridge'>" +
+                     "<mac address='06:7e:c6:00:05:68'/>" +
+                     "<source bridge='cloudbr1'/>" +
+                     "<target dev='vnet3'/>" +
+                     "<model type='virtio'/>" +
+                     "<alias name='net3'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>" +
+                     "</interface>" +
+                     "<serial type='pty'>" +
+                     "<source path='/dev/pts/3'/>" +
+                     "<target port='0'/>" +
+                     "<alias name='serial0'/>" +
+                     "</serial>" +
+                     "<console type='pty' tty='/dev/pts/3'>" +
+                     "<source path='/dev/pts/3'/>" +
+                     "<target type='serial' port='0'/>" +
+                     "<alias name='serial0'/>" +
+                     "</console>" +
+                     "<channel type='unix'>" +
+                     "<source mode='bind' path='/var/lib/libvirt/qemu/s-2970-VM.agent'/>" +
+                     "<target type='virtio' name='s-2970-VM.vport'/>" +
+                     "<alias name='channel0'/>" +
+                     "<address type='virtio-serial' controller='0' bus='0' port='1'/>" +
+                     "</channel>" +
+                     "<input type='tablet' bus='usb'>" +
+                     "<alias name='input0'/>" +
+                     "</input>" +
+                     "<input type='mouse' bus='ps2'/>" +
+                     "<graphics type='vnc' port='" + vncPort + "' autoport='yes' listen='0.0.0.0'>" +
+                     "<listen type='address' address='0.0.0.0'/>" +
+                     "</graphics>" +
+                     "<video>" +
+                     "<model type='cirrus' vram='9216' heads='1'/>" +
+                     "<alias name='video0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>" +
+                     "</video>" +
+                     "<memballoon model='virtio'>" +
+                     "<alias name='balloon0'/>" +
+                     "<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>" +
+                     "</memballoon>" +
+                     "</devices>" +
+                     "<seclabel type='none'/>" +
+                     "</domain>";
+
+        LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
+        parser.parseDomainXML(xml);
+
+        assertEquals(vncPort - 5900, (int)parser.getVncPort());
+
+        List<DiskDef> disks = parser.getDisks();
+        /* Disk 0 is the first disk, the QCOW2 file backed virto disk */
+        int diskId = 0;
+
+        assertEquals(diskLabel, disks.get(diskId).getDiskLabel());
+        assertEquals(diskPath, disks.get(diskId).getDiskPath());
+        assertEquals(diskCache, disks.get(diskId).getCacheMode());
+        assertEquals(diskBus, disks.get(diskId).getBusType());
+        assertEquals(diskType, disks.get(diskId).getDiskType());
+        assertEquals(deviceType, disks.get(diskId).getDeviceType());
+        assertEquals(diskFormat, disks.get(diskId).getDiskFormatType());
+    }
+}
\ No newline at end of file


[41/50] [abbrv] Revert "CLOUDSTACK-6003 fixing plus refactoring dispatcher" as it breaks API dispatching for commands having Map as a parameter type

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/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 436737a..21c38ce 100644
--- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
+++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
@@ -56,7 +56,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiDBUtils;
-import com.cloud.api.dispatch.DispatchChainFactory;
+import com.cloud.api.ApiDispatcher;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenter.NetworkType;
@@ -124,10 +124,8 @@ import com.google.gson.reflect.TypeToken;
 @Local(value = {AutoScaleService.class, AutoScaleManager.class})
 public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService {
     private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
-    private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1);
+    private ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1);
 
-    @Inject()
-    protected DispatchChainFactory dispatchChainFactory = null;
     @Inject
     EntityManager _entityMgr;
     @Inject
@@ -181,35 +179,35 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @Inject
     LoadBalancingRulesService _loadBalancingRulesService;
 
-    public List<AutoScaleCounter> getSupportedAutoScaleCounters(final long networkid) {
-        final String capability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName());
+    public List<AutoScaleCounter> getSupportedAutoScaleCounters(long networkid) {
+        String capability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName());
         if (capability == null) {
             return null;
         }
-        final Gson gson = new Gson();
-        final java.lang.reflect.Type listType = new TypeToken<List<AutoScaleCounter>>() {
+        Gson gson = new Gson();
+        java.lang.reflect.Type listType = new TypeToken<List<AutoScaleCounter>>() {
         }.getType();
-        final List<AutoScaleCounter> result = gson.fromJson(capability, listType);
+        List<AutoScaleCounter> result = gson.fromJson(capability, listType);
         return result;
     }
 
-    public void validateAutoScaleCounters(final long networkid, final List<Counter> counters, final List<Pair<String, String>> counterParamPassed) {
-        final List<AutoScaleCounter> supportedCounters = getSupportedAutoScaleCounters(networkid);
+    public void validateAutoScaleCounters(long networkid, List<Counter> counters, List<Pair<String, String>> counterParamPassed) {
+        List<AutoScaleCounter> supportedCounters = getSupportedAutoScaleCounters(networkid);
         if (supportedCounters == null) {
             throw new InvalidParameterException("AutoScale is not supported in the network");
         }
-        for (final Counter counter : counters) {
-            final String counterName = counter.getSource().name().toString();
+        for (Counter counter : counters) {
+            String counterName = counter.getSource().name().toString();
             boolean isCounterSupported = false;
-            for (final AutoScaleCounter autoScaleCounter : supportedCounters) {
+            for (AutoScaleCounter autoScaleCounter : supportedCounters) {
                 if (autoScaleCounter.getName().equals(counterName)) {
                     isCounterSupported = true;
-                    final List<AutoScaleCounterParam> counterParams = autoScaleCounter.getParamList();
-                    for (final AutoScaleCounterParam autoScaleCounterParam : counterParams) {
-                        final boolean isRequiredParameter = autoScaleCounterParam.getRequired();
+                    List<AutoScaleCounterParam> counterParams = autoScaleCounter.getParamList();
+                    for (AutoScaleCounterParam autoScaleCounterParam : counterParams) {
+                        boolean isRequiredParameter = autoScaleCounterParam.getRequired();
                         if (isRequiredParameter) {
                             boolean isRequiredParamPresent = false;
-                            for (final Pair<String, String> pair : counterParamPassed) {
+                            for (Pair<String, String> pair : counterParamPassed) {
                                 if (pair.first().equals(autoScaleCounterParam.getParamName()))
                                     isRequiredParamPresent = true;
 
@@ -229,9 +227,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         }
     }
 
-    private <VO extends ControlledEntity> VO getEntityInDatabase(final Account caller, final String paramName, final Long id, final GenericDao<VO, Long> dao) {
+    private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller, String paramName, Long id, GenericDao<VO, Long> dao) {
 
-        final VO vo = dao.findById(id);
+        VO vo = dao.findById(id);
 
         if (vo == null) {
             throw new InvalidParameterValueException("Unable to find " + paramName);
@@ -242,27 +240,27 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         return vo;
     }
 
-    private boolean isAutoScaleScaleUpPolicy(final AutoScalePolicy policyVO) {
+    private boolean isAutoScaleScaleUpPolicy(AutoScalePolicy policyVO) {
         return policyVO.getAction().equals("scaleup");
     }
 
-    private List<AutoScalePolicyVO> getAutoScalePolicies(final String paramName, final List<Long> policyIds, final List<Counter> counters, final int interval, final boolean scaleUpPolicies) {
-        final SearchBuilder<AutoScalePolicyVO> policySearch = _autoScalePolicyDao.createSearchBuilder();
+    private List<AutoScalePolicyVO> getAutoScalePolicies(String paramName, List<Long> policyIds, List<Counter> counters, int interval, boolean scaleUpPolicies) {
+        SearchBuilder<AutoScalePolicyVO> policySearch = _autoScalePolicyDao.createSearchBuilder();
         policySearch.and("ids", policySearch.entity().getId(), Op.IN);
         policySearch.done();
-        final SearchCriteria<AutoScalePolicyVO> sc = policySearch.create();
+        SearchCriteria<AutoScalePolicyVO> sc = policySearch.create();
 
         sc.setParameters("ids", policyIds.toArray(new Object[0]));
-        final List<AutoScalePolicyVO> policies = _autoScalePolicyDao.search(sc, null);
+        List<AutoScalePolicyVO> policies = _autoScalePolicyDao.search(sc, null);
 
         int prevQuietTime = 0;
 
-        for (final AutoScalePolicyVO policy : policies) {
-            final int quietTime = policy.getQuietTime();
+        for (AutoScalePolicyVO policy : policies) {
+            int quietTime = policy.getQuietTime();
             if (prevQuietTime == 0) {
                 prevQuietTime = quietTime;
             }
-            final int duration = policy.getDuration();
+            int duration = policy.getDuration();
             if (duration < interval) {
                 throw new InvalidParameterValueException("duration : " + duration + " specified in a policy cannot be less than vm group's interval : " + interval);
             }
@@ -280,11 +278,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
                     throw new InvalidParameterValueException("Only scaledown policies can be specified in scaledownpolicyids");
                 }
             }
-            final List<AutoScalePolicyConditionMapVO> policyConditionMapVOs = _autoScalePolicyConditionMapDao.listByAll(policy.getId(), null);
-            for (final AutoScalePolicyConditionMapVO policyConditionMapVO : policyConditionMapVOs) {
-                final long conditionid = policyConditionMapVO.getConditionId();
-                final Condition condition = _conditionDao.findById(conditionid);
-                final Counter counter = _counterDao.findById(condition.getCounterid());
+            List<AutoScalePolicyConditionMapVO> policyConditionMapVOs = _autoScalePolicyConditionMapDao.listByAll(policy.getId(), null);
+            for (AutoScalePolicyConditionMapVO policyConditionMapVO : policyConditionMapVOs) {
+                long conditionid = policyConditionMapVO.getConditionId();
+                Condition condition = _conditionDao.findById(conditionid);
+                Counter counter = _counterDao.findById(condition.getCounterid());
                 counters.add(counter);
             }
         }
@@ -293,11 +291,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @DB
     protected AutoScaleVmProfileVO checkValidityAndPersist(AutoScaleVmProfileVO vmProfile) {
-        final long templateId = vmProfile.getTemplateId();
-        final long autoscaleUserId = vmProfile.getAutoScaleUserId();
-        final int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
+        long templateId = vmProfile.getTemplateId();
+        long autoscaleUserId = vmProfile.getAutoScaleUserId();
+        int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
 
-        final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
+        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
         // Make sure a valid template ID was specified
         if (template == null) {
             throw new InvalidParameterValueException("Unable to use the given template.");
@@ -307,14 +305,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             throw new InvalidParameterValueException("Destroy Vm Grace Period cannot be less than 0.");
         }
 
-        final User user = _userDao.findById(autoscaleUserId);
+        User user = _userDao.findById(autoscaleUserId);
         if (user.getAccountId() != vmProfile.getAccountId()) {
             throw new InvalidParameterValueException("AutoScale User id does not belong to the same account");
         }
 
-        final String apiKey = user.getApiKey();
-        final String secretKey = user.getSecretKey();
-        final String csUrl = ApiServiceConfiguration.ApiServletPath.value();
+        String apiKey = user.getApiKey();
+        String secretKey = user.getSecretKey();
+        String csUrl = ApiServiceConfiguration.ApiServletPath.value();
 
         if (apiKey == null) {
             throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
@@ -335,41 +333,39 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, eventDescription = "creating autoscale vm profile", create = true)
-    public AutoScaleVmProfile createAutoScaleVmProfile(final CreateAutoScaleVmProfileCmd cmd) {
+    public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd cmd) {
 
-        final Account owner = _accountDao.findById(cmd.getAccountId());
-        final Account caller = CallContext.current().getCallingAccount();
+        Account owner = _accountDao.findById(cmd.getAccountId());
+        Account caller = CallContext.current().getCallingAccount();
         _accountMgr.checkAccess(caller, null, true, owner);
 
-        final long zoneId = cmd.getZoneId();
-        final long serviceOfferingId = cmd.getServiceOfferingId();
-        final long autoscaleUserId = cmd.getAutoscaleUserId();
+        long zoneId = cmd.getZoneId();
+        long serviceOfferingId = cmd.getServiceOfferingId();
+        long autoscaleUserId = cmd.getAutoscaleUserId();
 
-        final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
+        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
 
         if (zone == null) {
             throw new InvalidParameterValueException("Unable to find zone by id");
         }
 
-        final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
         if (serviceOffering == null) {
             throw new InvalidParameterValueException("Unable to find service offering by id");
         }
 
         // validations
-        final HashMap<String, Object> deployParams = cmd.getDeployParamMap();
-        final Object networks = deployParams.get("networks");
-        if (networks != null && networks instanceof String && ((String)networks).length() > 0) {
+        HashMap<String, String> deployParams = cmd.getDeployParamMap();
+        if (deployParams.containsKey("networks") && deployParams.get("networks").length() > 0) {
             throw new InvalidParameterValueException(
                 "'networks' is not a valid parameter, network for an AutoScaled VM is chosen automatically. An autoscaled VM is deployed in the loadbalancer's network");
         }
-
         /*
          * Just for making sure the values are right in other deploy params.
          * For ex. if projectId is given as a string instead of an long value, this
          * will be throwing an error.
          */
-        dispatchChainFactory.getStandardDispatchChain().dispatch(new DeployVMCmd(), deployParams);
+        ApiDispatcher.processParameters(new DeployVMCmd(), deployParams);
 
         AutoScaleVmProfileVO profileVO =
             new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(),
@@ -382,13 +378,13 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_UPDATE, eventDescription = "updating autoscale vm profile")
-    public AutoScaleVmProfile updateAutoScaleVmProfile(final UpdateAutoScaleVmProfileCmd cmd) {
-        final Long profileId = cmd.getId();
-        final Long templateId = cmd.getTemplateId();
-        final Long autoscaleUserId = cmd.getAutoscaleUserId();
-        final Map counterParamList = cmd.getCounterParamList();
+    public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd cmd) {
+        Long profileId = cmd.getId();
+        Long templateId = cmd.getTemplateId();
+        Long autoscaleUserId = cmd.getAutoscaleUserId();
+        Map counterParamList = cmd.getCounterParamList();
 
-        final Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod();
+        Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod();
 
         AutoScaleVmProfileVO vmProfile = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao);
 
@@ -429,13 +425,13 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_DELETE, eventDescription = "deleting autoscale vm profile")
-    public boolean deleteAutoScaleVmProfile(final long id) {
+    public boolean deleteAutoScaleVmProfile(long id) {
         /* Check if entity is in database */
         getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Profile", id, _autoScaleVmProfileDao);
         if (_autoScaleVmGroupDao.isProfileInUse(id)) {
             throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups");
         }
-        final boolean success = _autoScaleVmProfileDao.remove(id);
+        boolean success = _autoScaleVmProfileDao.remove(id);
         if (success) {
             s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
         }
@@ -443,22 +439,22 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public List<? extends AutoScaleVmProfile> listAutoScaleVmProfiles(final ListAutoScaleVmProfilesCmd cmd) {
-        final Long id = cmd.getId();
-        final Long templateId = cmd.getTemplateId();
-        final String otherDeployParams = cmd.getOtherDeployParams();
-        final Long serviceOffId = cmd.getServiceOfferingId();
-        final Long zoneId = cmd.getZoneId();
+    public List<? extends AutoScaleVmProfile> listAutoScaleVmProfiles(ListAutoScaleVmProfilesCmd cmd) {
+        Long id = cmd.getId();
+        Long templateId = cmd.getTemplateId();
+        String otherDeployParams = cmd.getOtherDeployParams();
+        Long serviceOffId = cmd.getServiceOfferingId();
+        Long zoneId = cmd.getZoneId();
 
-        final SearchWrapper<AutoScaleVmProfileVO> searchWrapper = new SearchWrapper<AutoScaleVmProfileVO>(_autoScaleVmProfileDao, AutoScaleVmProfileVO.class, cmd, cmd.getId());
-        final SearchBuilder<AutoScaleVmProfileVO> sb = searchWrapper.getSearchBuilder();
+        SearchWrapper<AutoScaleVmProfileVO> searchWrapper = new SearchWrapper<AutoScaleVmProfileVO>(_autoScaleVmProfileDao, AutoScaleVmProfileVO.class, cmd, cmd.getId());
+        SearchBuilder<AutoScaleVmProfileVO> sb = searchWrapper.getSearchBuilder();
 
         sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
         sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
         sb.and("serviceOfferingId", sb.entity().getServiceOfferingId(), SearchCriteria.Op.EQ);
         sb.and("otherDeployParams", sb.entity().getOtherDeployParams(), SearchCriteria.Op.LIKE);
         sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
-        final SearchCriteria<AutoScaleVmProfileVO> sc = searchWrapper.buildSearchCriteria();
+        SearchCriteria<AutoScaleVmProfileVO> sc = searchWrapper.buildSearchCriteria();
 
         if (id != null) {
             sc.setParameters("id", id);
@@ -496,19 +492,19 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
         return Transaction.execute(new TransactionCallback<AutoScalePolicyVO>() {
             @Override
-            public AutoScalePolicyVO doInTransaction(final TransactionStatus status) {
-                final AutoScalePolicyVO autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVOFinal);
+            public AutoScalePolicyVO doInTransaction(TransactionStatus status) {
+                AutoScalePolicyVO autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVOFinal);
 
                 if (conditionIds != null) {
-                    final SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
+                    SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
                     conditionsSearch.and("ids", conditionsSearch.entity().getId(), Op.IN);
                     conditionsSearch.done();
-                    final SearchCriteria<ConditionVO> sc = conditionsSearch.create();
+                    SearchCriteria<ConditionVO> sc = conditionsSearch.create();
 
                     sc.setParameters("ids", conditionIds.toArray(new Object[0]));
-                    final List<ConditionVO> conditions = _conditionDao.search(sc, null);
+                    List<ConditionVO> conditions = _conditionDao.search(sc, null);
 
-                    final ControlledEntity[] sameOwnerEntities = conditions.toArray(new ControlledEntity[conditions.size() + 1]);
+                    ControlledEntity[] sameOwnerEntities = conditions.toArray(new ControlledEntity[conditions.size() + 1]);
                     sameOwnerEntities[sameOwnerEntities.length - 1] = autoScalePolicyVO;
                     _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEntities);
 
@@ -517,8 +513,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
                         throw new InvalidParameterValueException("Unable to find the condition specified");
                     }
 
-                    final ArrayList<Long> counterIds = new ArrayList<Long>();
-                    for (final ConditionVO condition : conditions) {
+                    ArrayList<Long> counterIds = new ArrayList<Long>();
+                    for (ConditionVO condition : conditions) {
                         if (counterIds.contains(condition.getCounterid())) {
                             throw new InvalidParameterValueException(
                                 "atleast two conditions in the conditionids have the same counter. It is not right to apply two different conditions for the same counter");
@@ -529,8 +525,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
                     /* For update case remove the existing mappings and create fresh ones */
                     _autoScalePolicyConditionMapDao.removeByAutoScalePolicyId(autoScalePolicyVO.getId());
 
-                    for (final Long conditionId : conditionIds) {
-                        final AutoScalePolicyConditionMapVO policyConditionMapVO = new AutoScalePolicyConditionMapVO(autoScalePolicyVO.getId(), conditionId);
+                    for (Long conditionId : conditionIds) {
+                        AutoScalePolicyConditionMapVO policyConditionMapVO = new AutoScalePolicyConditionMapVO(autoScalePolicyVO.getId(), conditionId);
                         _autoScalePolicyConditionMapDao.persist(policyConditionMapVO);
                     }
                 }
@@ -542,9 +538,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_CREATE, eventDescription = "creating autoscale policy", create = true)
-    public AutoScalePolicy createAutoScalePolicy(final CreateAutoScalePolicyCmd cmd) {
+    public AutoScalePolicy createAutoScalePolicy(CreateAutoScalePolicyCmd cmd) {
 
-        final int duration = cmd.getDuration();
+        int duration = cmd.getDuration();
         Integer quietTime = cmd.getQuietTime();
         String action = cmd.getAction();
 
@@ -577,7 +573,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
         return Transaction.execute(new TransactionCallback<Boolean>() {
             @Override
-            public Boolean doInTransaction(final TransactionStatus status) {
+            public Boolean doInTransaction(TransactionStatus status) {
                 boolean success = true;
                 success = _autoScalePolicyDao.remove(id);
                 if (!success) {
@@ -596,11 +592,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         });
     }
 
-    public void checkCallerAccess(final String accountName, final Long domainId) {
-        final Account caller = CallContext.current().getCallingAccount();
-        final Account owner = _accountDao.findActiveAccount(accountName, domainId);
+    public void checkCallerAccess(String accountName, Long domainId) {
+        Account caller = CallContext.current().getCallingAccount();
+        Account owner = _accountDao.findActiveAccount(accountName, domainId);
         if (owner == null) {
-            final List<String> idList = new ArrayList<String>();
+            List<String> idList = new ArrayList<String>();
             idList.add(ApiDBUtils.findDomainById(domainId).getUuid());
             throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain with specifed domainId");
         }
@@ -617,23 +613,23 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         ListProjectResourcesCriteria listProjectResourcesCriteria;
         Filter searchFilter;
 
-        public SearchWrapper(final GenericDao<VO, Long> dao, final Class<VO> entityClass, final BaseListAccountResourcesCmd cmd, final Long id) {
+        public SearchWrapper(GenericDao<VO, Long> dao, Class<VO> entityClass, BaseListAccountResourcesCmd cmd, Long id) {
             this.dao = dao;
             this.searchBuilder = dao.createSearchBuilder();
             domainId = cmd.getDomainId();
-            final String accountName = cmd.getAccountName();
+            String accountName = cmd.getAccountName();
             isRecursive = cmd.isRecursive();
-            final boolean listAll = cmd.listAll();
-            final long startIndex = cmd.getStartIndex();
-            final long pageSizeVal = cmd.getPageSizeVal();
-            final Account caller = CallContext.current().getCallingAccount();
+            boolean listAll = cmd.listAll();
+            long startIndex = cmd.getStartIndex();
+            long pageSizeVal = cmd.getPageSizeVal();
+            Account caller = CallContext.current().getCallingAccount();
 
-            final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
+            Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
                 new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
             _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false);
             domainId = domainIdRecursiveListProject.first();
             isRecursive = domainIdRecursiveListProject.second();
-            final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
+            ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
             _accountMgr.buildACLSearchBuilder(searchBuilder, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
             searchFilter = new Filter(entityClass, "id", false, startIndex, pageSizeVal);
         }
@@ -654,30 +650,30 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public List<? extends AutoScalePolicy> listAutoScalePolicies(final ListAutoScalePoliciesCmd cmd) {
-        final SearchWrapper<AutoScalePolicyVO> searchWrapper = new SearchWrapper<AutoScalePolicyVO>(_autoScalePolicyDao, AutoScalePolicyVO.class, cmd, cmd.getId());
-        final SearchBuilder<AutoScalePolicyVO> sb = searchWrapper.getSearchBuilder();
-        final Long id = cmd.getId();
-        final Long conditionId = cmd.getConditionId();
-        final String action = cmd.getAction();
-        final Long vmGroupId = cmd.getVmGroupId();
+    public List<? extends AutoScalePolicy> listAutoScalePolicies(ListAutoScalePoliciesCmd cmd) {
+        SearchWrapper<AutoScalePolicyVO> searchWrapper = new SearchWrapper<AutoScalePolicyVO>(_autoScalePolicyDao, AutoScalePolicyVO.class, cmd, cmd.getId());
+        SearchBuilder<AutoScalePolicyVO> sb = searchWrapper.getSearchBuilder();
+        Long id = cmd.getId();
+        Long conditionId = cmd.getConditionId();
+        String action = cmd.getAction();
+        Long vmGroupId = cmd.getVmGroupId();
 
         sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
         sb.and("action", sb.entity().getAction(), SearchCriteria.Op.EQ);
 
         if (conditionId != null) {
-            final SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
+            SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
             asPolicyConditionSearch.and("conditionId", asPolicyConditionSearch.entity().getConditionId(), SearchCriteria.Op.EQ);
             sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
         }
 
         if (vmGroupId != null) {
-            final SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
+            SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
             asVmGroupPolicySearch.and("vmGroupId", asVmGroupPolicySearch.entity().getVmGroupId(), SearchCriteria.Op.EQ);
             sb.join("asVmGroupPolicySearch", asVmGroupPolicySearch, sb.entity().getId(), asVmGroupPolicySearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
         }
 
-        final SearchCriteria<AutoScalePolicyVO> sc = searchWrapper.buildSearchCriteria();
+        SearchCriteria<AutoScalePolicyVO> sc = searchWrapper.buildSearchCriteria();
 
         if (id != null) {
             sc.setParameters("id", id);
@@ -700,11 +696,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_UPDATE, eventDescription = "updating autoscale policy")
-    public AutoScalePolicy updateAutoScalePolicy(final UpdateAutoScalePolicyCmd cmd) {
-        final Long policyId = cmd.getId();
-        final Integer duration = cmd.getDuration();
-        final Integer quietTime = cmd.getQuietTime();
-        final List<Long> conditionIds = cmd.getConditionIds();
+    public AutoScalePolicy updateAutoScalePolicy(UpdateAutoScalePolicyCmd cmd) {
+        Long policyId = cmd.getId();
+        Integer duration = cmd.getDuration();
+        Integer quietTime = cmd.getQuietTime();
+        List<Long> conditionIds = cmd.getConditionIds();
         AutoScalePolicyVO policy = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Policy", policyId, _autoScalePolicyDao);
 
         if (duration != null) {
@@ -715,9 +711,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             policy.setQuietTime(quietTime);
         }
 
-        final List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyList = _autoScaleVmGroupPolicyMapDao.listByPolicyId(policyId);
-        for (final AutoScaleVmGroupPolicyMapVO vmGroupPolicy : vmGroupPolicyList) {
-            final AutoScaleVmGroupVO vmGroupVO = _autoScaleVmGroupDao.findById(vmGroupPolicy.getVmGroupId());
+        List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyList = _autoScaleVmGroupPolicyMapDao.listByPolicyId(policyId);
+        for (AutoScaleVmGroupPolicyMapVO vmGroupPolicy : vmGroupPolicyList) {
+            AutoScaleVmGroupVO vmGroupVO = _autoScaleVmGroupDao.findById(vmGroupPolicy.getVmGroupId());
             if (vmGroupVO == null) {
                 s_logger.warn("Stale database entry! There is an entry in VmGroupPolicyMap but the vmGroup is missing:" + vmGroupPolicy.getVmGroupId());
 
@@ -739,18 +735,18 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE, eventDescription = "creating autoscale vm group", create = true)
-    public AutoScaleVmGroup createAutoScaleVmGroup(final CreateAutoScaleVmGroupCmd cmd) {
-        final int minMembers = cmd.getMinMembers();
-        final int maxMembers = cmd.getMaxMembers();
+    public AutoScaleVmGroup createAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) {
+        int minMembers = cmd.getMinMembers();
+        int maxMembers = cmd.getMaxMembers();
         Integer interval = cmd.getInterval();
 
         if (interval == null) {
             interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME;
         }
 
-        final LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
+        LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
 
-        final Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
+        Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
 
         if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancer.getId())) {
             throw new InvalidParameterValueException("an AutoScaleVmGroup is already attached to the lb rule, the existing vm group has to be first deleted");
@@ -771,23 +767,23 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public boolean configureAutoScaleVmGroup(final CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException {
+    public boolean configureAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException {
         return configureAutoScaleVmGroup(cmd.getEntityId(), AutoScaleVmGroup.State_New);
     }
 
-    public boolean isLoadBalancerBasedAutoScaleVmGroup(final AutoScaleVmGroup vmGroup) {
+    public boolean isLoadBalancerBasedAutoScaleVmGroup(AutoScaleVmGroup vmGroup) {
         return vmGroup.getLoadBalancerId() != null;
     }
 
-    private boolean configureAutoScaleVmGroup(final long vmGroupid, final String currentState) throws ResourceUnavailableException {
-        final AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
+    private boolean configureAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException {
+        AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
 
         if (isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
             try {
                 return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid, currentState);
-            } catch (final ResourceUnavailableException re) {
+            } catch (ResourceUnavailableException re) {
                 throw re;
-            } catch (final Exception e) {
+            } catch (Exception e) {
                 s_logger.warn("Exception during configureLbAutoScaleVmGroup in lb rules manager", e);
                 return false;
             }
@@ -801,20 +797,20 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DELETE, eventDescription = "deleting autoscale vm group")
     public boolean deleteAutoScaleVmGroup(final long id) {
-        final AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
+        AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
 
         if (autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
             /* This condition is for handling failures during creation command */
             return _autoScaleVmGroupDao.remove(id);
         }
-        final String bakupState = autoScaleVmGroupVO.getState();
+        String bakupState = autoScaleVmGroupVO.getState();
         autoScaleVmGroupVO.setState(AutoScaleVmGroup.State_Revoke);
         _autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
         boolean success = false;
 
         try {
             success = configureAutoScaleVmGroup(id, bakupState);
-        } catch (final ResourceUnavailableException e) {
+        } catch (ResourceUnavailableException e) {
             autoScaleVmGroupVO.setState(bakupState);
             _autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
         } finally {
@@ -826,7 +822,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
         return Transaction.execute(new TransactionCallback<Boolean>() {
             @Override
-            public Boolean doInTransaction(final TransactionStatus status) {
+            public Boolean doInTransaction(TransactionStatus status) {
                 boolean success = _autoScaleVmGroupDao.remove(id);
 
                 if (!success) {
@@ -848,15 +844,15 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public List<? extends AutoScaleVmGroup> listAutoScaleVmGroups(final ListAutoScaleVmGroupsCmd cmd) {
-        final Long id = cmd.getId();
-        final Long policyId = cmd.getPolicyId();
-        final Long loadBalancerId = cmd.getLoadBalancerId();
-        final Long profileId = cmd.getProfileId();
-        final Long zoneId = cmd.getZoneId();
+    public List<? extends AutoScaleVmGroup> listAutoScaleVmGroups(ListAutoScaleVmGroupsCmd cmd) {
+        Long id = cmd.getId();
+        Long policyId = cmd.getPolicyId();
+        Long loadBalancerId = cmd.getLoadBalancerId();
+        Long profileId = cmd.getProfileId();
+        Long zoneId = cmd.getZoneId();
 
-        final SearchWrapper<AutoScaleVmGroupVO> searchWrapper = new SearchWrapper<AutoScaleVmGroupVO>(_autoScaleVmGroupDao, AutoScaleVmGroupVO.class, cmd, cmd.getId());
-        final SearchBuilder<AutoScaleVmGroupVO> sb = searchWrapper.getSearchBuilder();
+        SearchWrapper<AutoScaleVmGroupVO> searchWrapper = new SearchWrapper<AutoScaleVmGroupVO>(_autoScaleVmGroupDao, AutoScaleVmGroupVO.class, cmd, cmd.getId());
+        SearchBuilder<AutoScaleVmGroupVO> sb = searchWrapper.getSearchBuilder();
 
         sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
         sb.and("loadBalancerId", sb.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
@@ -864,12 +860,12 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
 
         if (policyId != null) {
-            final SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
+            SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
             asVmGroupPolicySearch.and("policyId", asVmGroupPolicySearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
             sb.join("asVmGroupPolicySearch", asVmGroupPolicySearch, sb.entity().getId(), asVmGroupPolicySearch.entity().getVmGroupId(), JoinBuilder.JoinType.INNER);
         }
 
-        final SearchCriteria<AutoScaleVmGroupVO> sc = searchWrapper.buildSearchCriteria();
+        SearchCriteria<AutoScaleVmGroupVO> sc = searchWrapper.buildSearchCriteria();
         if (id != null) {
             sc.setParameters("id", id);
         }
@@ -891,14 +887,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @DB
     protected AutoScaleVmGroupVO checkValidityAndPersist(final AutoScaleVmGroupVO vmGroup, final List<Long> passedScaleUpPolicyIds,
         final List<Long> passedScaleDownPolicyIds) {
-        final int minMembers = vmGroup.getMinMembers();
-        final int maxMembers = vmGroup.getMaxMembers();
-        final int interval = vmGroup.getInterval();
-        final List<Counter> counters = new ArrayList<Counter>();
-        final List<AutoScalePolicyVO> policies = new ArrayList<AutoScalePolicyVO>();
+        int minMembers = vmGroup.getMinMembers();
+        int maxMembers = vmGroup.getMaxMembers();
+        int interval = vmGroup.getInterval();
+        List<Counter> counters = new ArrayList<Counter>();
+        List<AutoScalePolicyVO> policies = new ArrayList<AutoScalePolicyVO>();
         final List<Long> policyIds = new ArrayList<Long>();
-        final List<Long> currentScaleUpPolicyIds = new ArrayList<Long>();
-        final List<Long> currentScaleDownPolicyIds = new ArrayList<Long>();
+        List<Long> currentScaleUpPolicyIds = new ArrayList<Long>();
+        List<Long> currentScaleDownPolicyIds = new ArrayList<Long>();
         if (vmGroup.getCreated() != null) {
             ApiDBUtils.getAutoScaleVmGroupPolicyIds(vmGroup.getId(), currentScaleUpPolicyIds, currentScaleDownPolicyIds);
         }
@@ -937,26 +933,26 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             getAutoScalePolicies("scaledownpolicyid", currentScaleDownPolicyIds, counters, interval, false);
             policyIds.addAll(currentScaleDownPolicyIds);
         }
-        final AutoScaleVmProfileVO profileVO =
+        AutoScaleVmProfileVO profileVO =
             getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao);
 
-        final LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao);
+        LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao);
         validateAutoScaleCounters(loadBalancer.getNetworkId(), counters, profileVO.getCounterParams());
 
-        final ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]);
+        ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]);
         sameOwnerEntities[sameOwnerEntities.length - 2] = loadBalancer;
         sameOwnerEntities[sameOwnerEntities.length - 1] = profileVO;
         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEntities);
 
         return Transaction.execute(new TransactionCallback<AutoScaleVmGroupVO>() {
             @Override
-            public AutoScaleVmGroupVO doInTransaction(final TransactionStatus status) {
-                final AutoScaleVmGroupVO vmGroupNew = _autoScaleVmGroupDao.persist(vmGroup);
+            public AutoScaleVmGroupVO doInTransaction(TransactionStatus status) {
+                AutoScaleVmGroupVO vmGroupNew = _autoScaleVmGroupDao.persist(vmGroup);
 
                 if (passedScaleUpPolicyIds != null || passedScaleDownPolicyIds != null) {
                     _autoScaleVmGroupPolicyMapDao.removeByGroupId(vmGroupNew.getId());
 
-                    for (final Long policyId : policyIds) {
+                    for (Long policyId : policyIds) {
                         _autoScaleVmGroupPolicyMapDao.persist(new AutoScaleVmGroupPolicyMapVO(vmGroupNew.getId(), policyId));
                     }
                 }
@@ -969,14 +965,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_UPDATE, eventDescription = "updating autoscale vm group")
-    public AutoScaleVmGroup updateAutoScaleVmGroup(final UpdateAutoScaleVmGroupCmd cmd) {
-        final Long vmGroupId = cmd.getId();
-        final Integer minMembers = cmd.getMinMembers();
-        final Integer maxMembers = cmd.getMaxMembers();
-        final Integer interval = cmd.getInterval();
+    public AutoScaleVmGroup updateAutoScaleVmGroup(UpdateAutoScaleVmGroupCmd cmd) {
+        Long vmGroupId = cmd.getId();
+        Integer minMembers = cmd.getMinMembers();
+        Integer maxMembers = cmd.getMaxMembers();
+        Integer interval = cmd.getInterval();
 
-        final List<Long> scaleUpPolicyIds = cmd.getScaleUpPolicyIds();
-        final List<Long> scaleDownPolicyIds = cmd.getScaleDownPolicyIds();
+        List<Long> scaleUpPolicyIds = cmd.getScaleUpPolicyIds();
+        List<Long> scaleDownPolicyIds = cmd.getScaleDownPolicyIds();
 
         AutoScaleVmGroupVO vmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao);
 
@@ -1013,7 +1009,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @Override
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_ENABLE, eventDescription = "enabling autoscale vm group")
-    public AutoScaleVmGroup enableAutoScaleVmGroup(final Long id) {
+    public AutoScaleVmGroup enableAutoScaleVmGroup(Long id) {
         AutoScaleVmGroupVO vmGroup = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
         boolean success = false;
         if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Disabled)) {
@@ -1024,7 +1020,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             vmGroup.setState(AutoScaleVmGroup.State_Enabled);
             vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
             success = configureAutoScaleVmGroup(id, AutoScaleVmGroup.State_Disabled);
-        } catch (final ResourceUnavailableException e) {
+        } catch (ResourceUnavailableException e) {
             vmGroup.setState(AutoScaleVmGroup.State_Disabled);
             _autoScaleVmGroupDao.persist(vmGroup);
         } finally {
@@ -1040,7 +1036,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DISABLE, eventDescription = "disabling autoscale vm group")
     @DB
-    public AutoScaleVmGroup disableAutoScaleVmGroup(final Long id) {
+    public AutoScaleVmGroup disableAutoScaleVmGroup(Long id) {
         AutoScaleVmGroupVO vmGroup = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
         boolean success = false;
         if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Enabled)) {
@@ -1051,7 +1047,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             vmGroup.setState(AutoScaleVmGroup.State_Disabled);
             vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
             success = configureAutoScaleVmGroup(id, AutoScaleVmGroup.State_Enabled);
-        } catch (final ResourceUnavailableException e) {
+        } catch (ResourceUnavailableException e) {
             vmGroup.setState(AutoScaleVmGroup.State_Enabled);
             _autoScaleVmGroupDao.persist(vmGroup);
         } finally {
@@ -1067,14 +1063,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_COUNTER_CREATE, eventDescription = "Counter", create = true)
     @DB
-    public Counter createCounter(final CreateCounterCmd cmd) {
-        final String source = cmd.getSource().toLowerCase();
-        final String name = cmd.getName();
+    public Counter createCounter(CreateCounterCmd cmd) {
+        String source = cmd.getSource().toLowerCase();
+        String name = cmd.getName();
         Counter.Source src;
         // Validate Source
         try {
             src = Counter.Source.valueOf(source);
-        } catch (final Exception ex) {
+        } catch (Exception ex) {
             throw new InvalidParameterValueException("The Source " + source + " does not exist; Unable to create Counter");
         }
 
@@ -1089,21 +1085,21 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_CONDITION_CREATE, eventDescription = "Condition", create = true)
-    public Condition createCondition(final CreateConditionCmd cmd) {
+    public Condition createCondition(CreateConditionCmd cmd) {
         checkCallerAccess(cmd.getAccountName(), cmd.getDomainId());
-        final String opr = cmd.getRelationalOperator().toUpperCase();
-        final long cid = cmd.getCounterId();
-        final long threshold = cmd.getThreshold();
+        String opr = cmd.getRelationalOperator().toUpperCase();
+        long cid = cmd.getCounterId();
+        long threshold = cmd.getThreshold();
         Condition.Operator op;
         // Validate Relational Operator
         try {
             op = Condition.Operator.valueOf(opr);
-        } catch (final IllegalArgumentException ex) {
+        } catch (IllegalArgumentException ex) {
             throw new InvalidParameterValueException("The Operator " + opr + " does not exist; Unable to create Condition.");
         }
         // TODO - Validate threshold
 
-        final CounterVO counter = _counterDao.findById(cid);
+        CounterVO counter = _counterDao.findById(cid);
 
         if (counter == null) {
             throw new InvalidParameterValueException("Unable to find counter");
@@ -1118,29 +1114,29 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public List<? extends Counter> listCounters(final ListCountersCmd cmd) {
-        final String name = cmd.getName();
-        final Long id = cmd.getId();
+    public List<? extends Counter> listCounters(ListCountersCmd cmd) {
+        String name = cmd.getName();
+        Long id = cmd.getId();
         String source = cmd.getSource();
         if (source != null)
             source = source.toLowerCase();
 
-        final Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
+        Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
 
-        final List<CounterVO> counters = _counterDao.listCounters(id, name, source, cmd.getKeyword(), searchFilter);
+        List<CounterVO> counters = _counterDao.listCounters(id, name, source, cmd.getKeyword(), searchFilter);
 
         return counters;
     }
 
     @Override
-    public List<? extends Condition> listConditions(final ListConditionsCmd cmd) {
-        final Long id = cmd.getId();
-        final Long counterId = cmd.getCounterId();
-        final Long policyId = cmd.getPolicyId();
-        final SearchWrapper<ConditionVO> searchWrapper = new SearchWrapper<ConditionVO>(_conditionDao, ConditionVO.class, cmd, cmd.getId());
-        final SearchBuilder<ConditionVO> sb = searchWrapper.getSearchBuilder();
+    public List<? extends Condition> listConditions(ListConditionsCmd cmd) {
+        Long id = cmd.getId();
+        Long counterId = cmd.getCounterId();
+        Long policyId = cmd.getPolicyId();
+        SearchWrapper<ConditionVO> searchWrapper = new SearchWrapper<ConditionVO>(_conditionDao, ConditionVO.class, cmd, cmd.getId());
+        SearchBuilder<ConditionVO> sb = searchWrapper.getSearchBuilder();
         if (policyId != null) {
-            final SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
+            SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
             asPolicyConditionSearch.and("policyId", asPolicyConditionSearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
             sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getConditionId(),
                 JoinBuilder.JoinType.INNER);
@@ -1150,7 +1146,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         sb.and("counterId", sb.entity().getCounterid(), SearchCriteria.Op.EQ);
 
         // now set the SC criteria...
-        final SearchCriteria<ConditionVO> sc = searchWrapper.buildSearchCriteria();
+        SearchCriteria<ConditionVO> sc = searchWrapper.buildSearchCriteria();
 
         if (id != null) {
             sc.setParameters("id", id);
@@ -1169,22 +1165,22 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_COUNTER_DELETE, eventDescription = "counter")
-    public boolean deleteCounter(final long counterId) throws ResourceInUseException {
+    public boolean deleteCounter(long counterId) throws ResourceInUseException {
         // Verify Counter id
-        final CounterVO counter = _counterDao.findById(counterId);
+        CounterVO counter = _counterDao.findById(counterId);
         if (counter == null) {
             throw new InvalidParameterValueException("Unable to find Counter");
         }
 
         // Verify if it is used in any Condition
 
-        final ConditionVO condition = _conditionDao.findByCounterId(counterId);
+        ConditionVO condition = _conditionDao.findByCounterId(counterId);
         if (condition != null) {
             s_logger.info("Cannot delete counter " + counter.getName() + " as it is being used in a condition.");
             throw new ResourceInUseException("Counter is in use.");
         }
 
-        final boolean success = _counterDao.remove(counterId);
+        boolean success = _counterDao.remove(counterId);
         if (success) {
             s_logger.info("Successfully deleted counter with Id: " + counterId);
         }
@@ -1194,9 +1190,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_CONDITION_DELETE, eventDescription = "condition")
-    public boolean deleteCondition(final long conditionId) throws ResourceInUseException {
+    public boolean deleteCondition(long conditionId) throws ResourceInUseException {
         /* Check if entity is in database */
-        final ConditionVO condition = getEntityInDatabase(CallContext.current().getCallingAccount(), "Condition", conditionId, _conditionDao);
+        ConditionVO condition = getEntityInDatabase(CallContext.current().getCallingAccount(), "Condition", conditionId, _conditionDao);
         if (condition == null) {
             throw new InvalidParameterValueException("Unable to find Condition");
         }
@@ -1206,7 +1202,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             s_logger.info("Cannot delete condition " + conditionId + " as it is being used in a condition.");
             throw new ResourceInUseException("Cannot delete Condition when it is in use by one or more AutoScale Policies.");
         }
-        final boolean success = _conditionDao.remove(conditionId);
+        boolean success = _conditionDao.remove(conditionId);
         if (success) {
             s_logger.info("Successfully deleted condition " + condition.getId());
         }
@@ -1214,7 +1210,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public void cleanUpAutoScaleResources(final Long accountId) {
+    public void cleanUpAutoScaleResources(Long accountId) {
         // cleans Autoscale VmProfiles, AutoScale Policies and Conditions belonging to an account
         int count = 0;
         count = _autoScaleVmProfileDao.removeByAccountId(accountId);
@@ -1231,10 +1227,10 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         }
     }
 
-    private boolean checkConditionUp(final AutoScaleVmGroupVO asGroup, final Integer numVm) {
+    private boolean checkConditionUp(AutoScaleVmGroupVO asGroup, Integer numVm) {
         // check maximum
-        final Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
-        final Integer maxVm = asGroup.getMaxMembers();
+        Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
+        Integer maxVm = asGroup.getMaxMembers();
         if (currentVM + numVm > maxVm) {
             s_logger.warn("number of VM will greater than the maximum in this group if scaling up, so do nothing more");
             return false;
@@ -1242,9 +1238,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         return true;
     }
 
-    private boolean checkConditionDown(final AutoScaleVmGroupVO asGroup) {
-        final Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
-        final Integer minVm = asGroup.getMinMembers();
+    private boolean checkConditionDown(AutoScaleVmGroupVO asGroup) {
+        Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
+        Integer minVm = asGroup.getMinMembers();
         if (currentVM - 1 < minVm) {
             s_logger.warn("number of VM will less than the minimum in this group if scaling down, so do nothing more");
             return false;
@@ -1252,29 +1248,29 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         return true;
     }
 
-    private long createNewVM(final AutoScaleVmGroupVO asGroup) {
-        final AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
-        final long templateId = profileVo.getTemplateId();
-        final long serviceOfferingId = profileVo.getServiceOfferingId();
+    private long createNewVM(AutoScaleVmGroupVO asGroup) {
+        AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
+        long templateId = profileVo.getTemplateId();
+        long serviceOfferingId = profileVo.getServiceOfferingId();
         if (templateId == -1) {
             return -1;
         }
         // create new VM into DB
         try {
             //Verify that all objects exist before passing them to the service
-            final Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
+            Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
 
-            final DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
+            DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
             if (zone == null) {
                 throw new InvalidParameterValueException("Unable to find zone by id=" + profileVo.getZoneId());
             }
 
-            final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+            ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
             if (serviceOffering == null) {
                 throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
             }
 
-            final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
+            VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
             // Make sure a valid template ID was specified
             if (template == null) {
                 throw new InvalidParameterValueException("Unable to use template " + templateId);
@@ -1287,7 +1283,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             }
 
             UserVm vm = null;
-            final IpAddresses addrs = new IpAddresses(null, null);
+            IpAddresses addrs = new IpAddresses(null, null);
             if (zone.getNetworkType() == NetworkType.Basic) {
                 vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" +
                     getCurrentTimeStampString(),
@@ -1313,41 +1309,41 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             } else {
                 return -1;
             }
-        } catch (final InsufficientCapacityException ex) {
+        } catch (InsufficientCapacityException ex) {
             s_logger.info(ex);
             s_logger.trace(ex.getMessage(), ex);
             throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
-        } catch (final ResourceUnavailableException ex) {
+        } catch (ResourceUnavailableException ex) {
             s_logger.warn("Exception: ", ex);
             throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        } catch (final ConcurrentOperationException ex) {
+        } catch (ConcurrentOperationException ex) {
             s_logger.warn("Exception: ", ex);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (final ResourceAllocationException ex) {
+        } catch (ResourceAllocationException ex) {
             s_logger.warn("Exception: ", ex);
             throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
         }
     }
 
     private String getCurrentTimeStampString() {
-        final Date current = new Date();
-        final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        Date current = new Date();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 
         return sdf.format(current);
     }
 
-    private boolean startNewVM(final long vmId) {
+    private boolean startNewVM(long vmId) {
         try {
             CallContext.current().setEventDetails("Vm Id: " + vmId);
             _userVmManager.startVirtualMachine(vmId, null, null);
-        } catch (final ResourceUnavailableException ex) {
+        } catch (ResourceUnavailableException ex) {
             s_logger.warn("Exception: ", ex);
             throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        } catch (final ConcurrentOperationException ex) {
+        } catch (ConcurrentOperationException ex) {
             s_logger.warn("Exception: ", ex);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (final InsufficientCapacityException ex) {
-            final StringBuilder message = new StringBuilder(ex.getMessage());
+        } catch (InsufficientCapacityException ex) {
+            StringBuilder message = new StringBuilder(ex.getMessage());
             if (ex instanceof InsufficientServerCapacityException) {
                 if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
                     message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
@@ -1360,14 +1356,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         return true;
     }
 
-    private boolean assignLBruleToNewVm(final long vmId, final AutoScaleVmGroupVO asGroup) {
-        final List<Long> lstVmId = new ArrayList<Long>();
-        final long lbId = asGroup.getLoadBalancerId();
+    private boolean assignLBruleToNewVm(long vmId, AutoScaleVmGroupVO asGroup) {
+        List<Long> lstVmId = new ArrayList<Long>();
+        long lbId = asGroup.getLoadBalancerId();
 
-        final List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
+        List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
         if ((LbVmMapVos != null) && (LbVmMapVos.size() > 0)) {
-            for (final LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
-                final long instanceId = LbVmMapVo.getInstanceId();
+            for (LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
+                long instanceId = LbVmMapVo.getInstanceId();
                 if (instanceId == vmId) {
                     s_logger.warn("the new VM is already mapped to LB rule. What's wrong?");
                     return true;
@@ -1379,17 +1375,17 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     }
 
-    private long removeLBrule(final AutoScaleVmGroupVO asGroup) {
-        final long lbId = asGroup.getLoadBalancerId();
+    private long removeLBrule(AutoScaleVmGroupVO asGroup) {
+        long lbId = asGroup.getLoadBalancerId();
         long instanceId = -1;
-        final List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
+        List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
         if ((LbVmMapVos != null) && (LbVmMapVos.size() > 0)) {
-            for (final LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
+            for (LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
                 instanceId = LbVmMapVo.getInstanceId();
             }
         }
         // take last VM out of the list
-        final List<Long> lstVmId = new ArrayList<Long>();
+        List<Long> lstVmId = new ArrayList<Long>();
         if (instanceId != -1)
             lstVmId.add(instanceId);
         if (_loadBalancingRulesService.removeFromLoadBalancer(lbId, lstVmId))
@@ -1399,8 +1395,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
     }
 
     @Override
-    public void doScaleUp(final long groupId, final Integer numVm) {
-        final AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
+    public void doScaleUp(long groupId, Integer numVm) {
+        AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
         if (asGroup == null) {
             s_logger.error("Can not find the groupid " + groupId + " for scaling up");
             return;
@@ -1409,7 +1405,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             return;
         }
         for (int i = 0; i < numVm; i++) {
-            final long vmId = createNewVM(asGroup);
+            long vmId = createNewVM(asGroup);
             if (vmId == -1) {
                 s_logger.error("Can not deploy new VM for scaling up in the group "
                     + asGroup.getId() + ". Waiting for next round");
@@ -1418,14 +1414,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             if (startNewVM(vmId)) {
                 if (assignLBruleToNewVm(vmId, asGroup)) {
                     // persist to DB
-                    final AutoScaleVmGroupVmMapVO GroupVmVO = new AutoScaleVmGroupVmMapVO(
+                    AutoScaleVmGroupVmMapVO GroupVmVO = new AutoScaleVmGroupVmMapVO(
                         asGroup.getId(), vmId);
                     _autoScaleVmGroupVmMapDao.persist(GroupVmVO);
                     // update last_quiettime
-                    final List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao
+                    List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao
                         .listByVmGroupId(groupId);
-                    for (final AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
-                        final AutoScalePolicyVO vo = _autoScalePolicyDao
+                    for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
+                        AutoScalePolicyVO vo = _autoScalePolicyDao
                             .findById(GroupPolicyVO.getPolicyId());
                         if (vo.getAction().equals("scaleup")) {
                             vo.setLastQuiteTime(new Date());
@@ -1447,7 +1443,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
     @Override
     public void doScaleDown(final long groupId) {
-        final AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
+        AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
         if (asGroup == null) {
             s_logger.error("Can not find the groupid " + groupId + " for scaling up");
             return;
@@ -1457,14 +1453,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
         }
         final long vmId = removeLBrule(asGroup);
         if (vmId != -1) {
-            final long profileId = asGroup.getProfileId();
+            long profileId = asGroup.getProfileId();
 
             // update group-vm mapping
             _autoScaleVmGroupVmMapDao.remove(groupId, vmId);
             // update last_quiettime
-            final List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(groupId);
-            for (final AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
-                final AutoScalePolicyVO vo = _autoScalePolicyDao.findById(GroupPolicyVO.getPolicyId());
+            List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(groupId);
+            for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
+                AutoScalePolicyVO vo = _autoScalePolicyDao.findById(GroupPolicyVO.getPolicyId());
                 if (vo.getAction().equals("scaledown")) {
                     vo.setLastQuiteTime(new Date());
                     _autoScalePolicyDao.persist(vo);
@@ -1473,8 +1469,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
             }
 
             // get destroyvmgrace param
-            final AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
-            final Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
+            AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
+            Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
             if (destroyVmGracePeriod >= 0) {
                 _executor.schedule(new Runnable() {
                     @Override
@@ -1483,9 +1479,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
 
                             _userVmManager.destroyVm(vmId);
 
-                        } catch (final ResourceUnavailableException e) {
+                        } catch (ResourceUnavailableException e) {
                             e.printStackTrace();
-                        } catch (final ConcurrentOperationException e) {
+                        } catch (ConcurrentOperationException e) {
                             e.printStackTrace();
                         }
                     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/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 1673cac..6b81cfa 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -1362,7 +1362,8 @@ Listener, Configurable {
     private final static int DEFAULT_PRIORITY = 100;
     private final static int DEFAULT_DELTA = 2;
 
-    protected int getUpdatedPriority(final Network guestNetwork, final List<DomainRouterVO> routers, final DomainRouterVO exclude) throws InsufficientVirtualNetworkCapcityException {
+    protected int getUpdatedPriority(final Network guestNetwork, final List<DomainRouterVO> routers, final DomainRouterVO exclude)
+            throws InsufficientVirtualNetworkCapcityException {
         int priority;
         if (routers.size() == 0) {
             priority = DEFAULT_PRIORITY;
@@ -2564,7 +2565,8 @@ Listener, Configurable {
         }
     }
 
-    protected void finalizeIpAssocForNetwork(final Commands cmds, final VirtualRouter router, final Provider provider, final Long guestNetworkId, final Map<String, String> vlanMacAddress) {
+    protected void finalizeIpAssocForNetwork(final Commands cmds, final VirtualRouter router, final Provider provider, final Long guestNetworkId,
+            final Map<String, String> vlanMacAddress) {
 
         final ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(router, provider, guestNetworkId);
 
@@ -2792,7 +2794,8 @@ Listener, Configurable {
     }
 
     @Override
-    public DomainRouterVO stop(final VirtualRouter router, final boolean forced, final User user, final Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
+    public DomainRouterVO stop(final VirtualRouter router, final boolean forced, final User user, final Account caller) throws ConcurrentOperationException,
+            ResourceUnavailableException {
         s_logger.debug("Stopping router " + router);
         try {
             _itMgr.advanceStop(router.getUuid(), forced);
@@ -2973,7 +2976,8 @@ Listener, Configurable {
         });
     }
 
-    private void createDeleteIpAliasCommand(final DomainRouterVO router, final List<IpAliasTO> deleteIpAliasTOs, final List<IpAliasTO> createIpAliasTos, final long networkId, final Commands cmds) {
+    private void createDeleteIpAliasCommand(final DomainRouterVO router, final List<IpAliasTO> deleteIpAliasTOs, final List<IpAliasTO> createIpAliasTos, final long networkId,
+            final Commands cmds) {
         final String routerip = getRouterIpInNetwork(networkId, router.getId());
         final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
         final DeleteIpAliasCommand deleteIpaliasCmd = new DeleteIpAliasCommand(routerip, deleteIpAliasTOs, createIpAliasTos);
@@ -4160,7 +4164,7 @@ Listener, Configurable {
 
     //Checks if the router is at the required version
     // Compares MS version and router version
-    protected boolean checkRouterVersion(final VirtualRouter router){
+    protected boolean checkRouterVersion(final VirtualRouter router) {
         if(!routerVersionCheckEnabled.value()){
             //Router version check is disabled.
             return true;


[09/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Removed references to secondarystoragevmmanager from code that doesn't use it.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7f34282d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7f34282d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7f34282d

Branch: refs/heads/rbac
Commit: 7f34282dfa276909a537bd4a65155e99a1e2f04f
Parents: 4be3b99
Author: Alex Huang <al...@citrix.com>
Authored: Wed Jan 15 17:56:57 2014 -0800
Committer: Alex Huang <al...@citrix.com>
Committed: Wed Feb 5 01:39:15 2014 +0000

----------------------------------------------------------------------
 .../storage/test/ChildTestConfiguration.java    |   6 -
 .../com/cloud/hypervisor/guru/VMwareGuru.java   |  36 ++--
 .../vmware/manager/VmwareManagerImpl.java       |  94 ++++------
 .../vmware/VmwareDatacenterApiUnitTest.java     |   6 -
 .../IntegrationTestConfiguration.java           |   6 -
 .../com/cloud/resource/ResourceManagerImpl.java |  66 ++++---
 .../com/cloud/server/ManagementServerImpl.java  |  40 ++---
 .../com/cloud/storage/VolumeApiServiceImpl.java | 178 ++++---------------
 .../storage/download/DownloadMonitorImpl.java   |  29 +--
 .../secondary/SecondaryStorageListener.java     |   5 +-
 .../secondary/SecondaryStorageManagerImpl.java  |   5 +-
 .../storage/snapshot/SnapshotManagerImpl.java   |  66 +++----
 .../cloud/storage/upload/UploadMonitorImpl.java |  27 ++-
 .../com/cloud/template/TemplateManagerImpl.java | 133 ++++----------
 .../networkoffering/ChildTestConfiguration.java |   6 -
 15 files changed, 207 insertions(+), 496 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java
index 69d60c2..3af7df7 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java
@@ -79,7 +79,6 @@ import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
 import com.cloud.storage.dao.VolumeDaoImpl;
 import com.cloud.storage.dao.VolumeHostDaoImpl;
 import com.cloud.storage.download.DownloadMonitorImpl;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.template.TemplateManager;
 import com.cloud.user.AccountManager;
@@ -111,11 +110,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl;
 public class ChildTestConfiguration extends TestConfiguration {
 
     @Bean
-    public SecondaryStorageVmManager secondaryStoreageMgr() {
-        return Mockito.mock(SecondaryStorageVmManager.class);
-    }
-
-    @Bean
     public HostDao hostDao() {
         return Mockito.spy(new HostDaoImpl());
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index d72787c..9a30f18 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -27,8 +27,6 @@ import java.util.UUID;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.vm.dao.VMInstanceDao;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.framework.config.ConfigKey;
@@ -71,7 +69,6 @@ import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
 import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
 import com.cloud.secstorage.CommandExecLogDao;
@@ -95,41 +92,38 @@ import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VmDetailConstants;
 import com.cloud.vm.dao.NicDao;
+import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = HypervisorGuru.class)
 public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable {
     private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
 
     @Inject
-    NetworkDao _networkDao;
-    @Inject
-    GuestOSDao _guestOsDao;
-    @Inject
-    HostDao _hostDao;
+    private NetworkDao _networkDao;
     @Inject
-    HostDetailsDao _hostDetailsDao;
+    private GuestOSDao _guestOsDao;
     @Inject
-    CommandExecLogDao _cmdExecLogDao;
+    private HostDao _hostDao;
     @Inject
-    VmwareManager _vmwareMgr;
+    private HostDetailsDao _hostDetailsDao;
     @Inject
-    SecondaryStorageVmManager _secStorageMgr;
+    private CommandExecLogDao _cmdExecLogDao;
     @Inject
-    NetworkModel _networkMgr;
+    private VmwareManager _vmwareMgr;
     @Inject
-    ConfigurationDao _configDao;
+    private SecondaryStorageVmManager _secStorageMgr;
     @Inject
-    NicDao _nicDao;
+    private NetworkModel _networkMgr;
     @Inject
-    PhysicalNetworkDao _physicalNetworkDao;
+    private ConfigurationDao _configDao;
     @Inject
-    PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
+    private NicDao _nicDao;
     @Inject
-    VMInstanceDao _vmDao;
+    private PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
     @Inject
-    ClusterDao _clusterDao;
+    private VMInstanceDao _vmDao;
     @Inject
-    ClusterManager _clusterMgr;
+    private ClusterManager _clusterMgr;
 
     protected VMwareGuru() {
         super();
@@ -204,7 +198,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
             }
         }
 
-        long clusterId = this.getClusterId(vm.getId());
+        long clusterId = getClusterId(vm.getId());
         details.put(Config.VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
         details.put(Config.VmwareReserveMem.key(), VmwareReserveMemory.valueIn(clusterId).toString());
         to.setDetails(details);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 482e8a6..4f443bb 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -38,7 +38,6 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 
-import com.google.gson.Gson;
 import com.vmware.vim25.AboutInfo;
 import com.vmware.vim25.ManagedObjectReference;
 
@@ -75,7 +74,6 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.host.Host;
 import com.cloud.host.Status;
-import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
 import com.cloud.hypervisor.vmware.LegacyZoneVO;
@@ -104,11 +102,9 @@ import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
 import com.cloud.org.Cluster.ClusterType;
 import com.cloud.secstorage.CommandExecLogDao;
-import com.cloud.serializer.GsonHelper;
 import com.cloud.server.ConfigurationServer;
 import com.cloud.storage.JavaStorageLayer;
 import com.cloud.storage.StorageLayer;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.utils.FileUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
@@ -132,85 +128,77 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
     private static final long DEFAULT_HOST_SCAN_INTERVAL = 600000;     // every 10 minutes
 
     private long _hostScanInterval = DEFAULT_HOST_SCAN_INTERVAL;
-    int _timeout;
+    private int _timeout;
 
     private String _instance;
 
     @Inject
-    AgentManager _agentMgr;
+    private AgentManager _agentMgr;
     @Inject
-    protected NetworkModel _netMgr;
+    private NetworkModel _netMgr;
     @Inject
-    HostDao _hostDao;
+    private ClusterDao _clusterDao;
     @Inject
-    ClusterDao _clusterDao;
+    private ClusterDetailsDao _clusterDetailsDao;
     @Inject
-    ClusterDetailsDao _clusterDetailsDao;
+    private CommandExecLogDao _cmdExecLogDao;
     @Inject
-    CommandExecLogDao _cmdExecLogDao;
+    private DataStoreManager _dataStoreMgr;
     @Inject
-    SecondaryStorageVmManager _ssvmMgr;
+    private CiscoNexusVSMDeviceDao _nexusDao;
     @Inject
-    DataStoreManager _dataStoreMgr;
+    private ClusterVSMMapDao _vsmMapDao;
     @Inject
-    CiscoNexusVSMDeviceDao _nexusDao;
+    private ConfigurationDao _configDao;
     @Inject
-    ClusterVSMMapDao _vsmMapDao;
+    private ConfigurationServer _configServer;
     @Inject
-    ConfigurationDao _configDao;
+    private HypervisorCapabilitiesDao _hvCapabilitiesDao;
     @Inject
-    ConfigurationServer _configServer;
+    private DataCenterDao _dcDao;
     @Inject
-    HypervisorCapabilitiesDao _hvCapabilitiesDao;
+    private VmwareDatacenterDao _vmwareDcDao;
     @Inject
-    DataCenterDao _dcDao;
+    private VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
     @Inject
-    VmwareDatacenterDao _vmwareDcDao;
+    private LegacyZoneDao _legacyZoneDao;
     @Inject
-    VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
+    private ManagementServerHostPeerDao _mshostPeerDao;
     @Inject
-    LegacyZoneDao _legacyZoneDao;
-    @Inject
-    ManagementServerHostPeerDao _mshostPeerDao;
-    @Inject
-    ClusterManager _clusterMgr;
+    private ClusterManager _clusterMgr;
 
-    String _mountParent;
-    StorageLayer _storage;
-    String _privateNetworkVSwitchName = "vSwitch0";
+    private String _mountParent;
+    private StorageLayer _storage;
+    private final String _privateNetworkVSwitchName = "vSwitch0";
 
-    int _portsPerDvPortGroup = 256;
-    boolean _nexusVSwitchActive;
-    boolean _fullCloneFlag;
-    boolean _instanceNameFlag;
-    String _serviceConsoleName;
-    String _managemetPortGroupName;
-    String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
-    String _recycleHungWorker = "false";
-    long _hungWorkerTimeout = 7200000;        // 2 hour
-    int _additionalPortRangeStart;
-    int _additionalPortRangeSize;
-    int _routerExtraPublicNics = 2;
-    int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds
+    private int _portsPerDvPortGroup = 256;
+    private boolean _fullCloneFlag;
+    private boolean _instanceNameFlag;
+    private String _serviceConsoleName;
+    private String _managemetPortGroupName;
+    private String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
+    private String _recycleHungWorker = "false";
+    private int _additionalPortRangeStart;
+    private int _additionalPortRangeSize;
+    private int _routerExtraPublicNics = 2;
+    private int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds
 
-    String _reserveCpu = "false";
+    private String _reserveCpu = "false";
 
-    String _reserveMem = "false";
+    private String _reserveMem = "false";
 
-    String _rootDiskController = DiskControllerType.ide.toString();
+    private String _rootDiskController = DiskControllerType.ide.toString();
 
-    Map<String, String> _storageMounts = new HashMap<String, String>();
+    private final Map<String, String> _storageMounts = new HashMap<String, String>();
 
-    Random _rand = new Random(System.currentTimeMillis());
-    Gson _gson;
+    private final Random _rand = new Random(System.currentTimeMillis());
 
-    VmwareStorageManager _storageMgr;
-    GlobalLock _exclusiveOpLock = GlobalLock.getInternLock("vmware.exclusive.op");
+    private final VmwareStorageManager _storageMgr;
+    private final GlobalLock _exclusiveOpLock = GlobalLock.getInternLock("vmware.exclusive.op");
 
     private final ScheduledExecutorService _hostScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vmware-Host-Scan"));
 
     public VmwareManagerImpl() {
-        _gson = GsonHelper.getGsonLogger();
         _storageMgr = new VmwareStorageManagerImpl(this);
     }
 
@@ -310,10 +298,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
             _recycleHungWorker = "false";
         }
 
-        value = _configDao.getValue(Config.VmwareHungWorkerTimeout.key());
-        if (value != null)
-            _hungWorkerTimeout = Long.parseLong(value) * 1000;
-
         _rootDiskController = _configDao.getValue(Config.VmwareRootDiskControllerType.key());
         if (_rootDiskController == null || _rootDiskController.isEmpty()) {
             _rootDiskController = DiskControllerType.ide.toString();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
index 4a00489..c2002ff 100644
--- a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
+++ b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
@@ -85,7 +85,6 @@ import com.cloud.org.Cluster.ClusterType;
 import com.cloud.org.Managed.ManagedState;
 import com.cloud.secstorage.CommandExecLogDao;
 import com.cloud.server.ConfigurationServer;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountService;
@@ -364,11 +363,6 @@ public class VmwareDatacenterApiUnitTest {
         }
 
         @Bean
-        public SecondaryStorageVmManager secondaryStorageVmManager() {
-            return Mockito.mock(SecondaryStorageVmManager.class);
-        }
-
-        @Bean
         public CommandExecLogDao commandExecLogDao() {
             return Mockito.mock(CommandExecLogDao.class);
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
index 1a53c17..954a37e 100644
--- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
@@ -259,7 +259,6 @@ import com.cloud.storage.dao.VMTemplateHostDaoImpl;
 import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
 import com.cloud.storage.dao.VolumeDaoImpl;
 import com.cloud.storage.dao.VolumeHostDaoImpl;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.snapshot.SnapshotApiService;
 import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.tags.dao.ResourceTagDao;
@@ -624,11 +623,6 @@ public class IntegrationTestConfiguration {
     }
 
     @Bean
-    public SecondaryStorageVmManager secondaryStorageVmManager() {
-        return Mockito.mock(SecondaryStorageVmManager.class);
-    }
-
-    @Bean
     public Site2SiteVpnManager site2SiteVpnManager() {
         return Mockito.mock(Site2SiteVpnManager.class);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index c9e2e7a..79eb1cb 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -47,7 +47,6 @@ import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
 import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.region.dao.RegionDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
@@ -129,7 +128,6 @@ import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.GuestOSCategoryDao;
 import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.User;
@@ -168,55 +166,51 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
     Gson _gson;
 
     @Inject
-    AccountManager _accountMgr;
+    private AccountManager _accountMgr;
     @Inject
-    AgentManager _agentMgr;
+    private AgentManager _agentMgr;
     @Inject
-    StorageManager _storageMgr;
+    private StorageManager _storageMgr;
     @Inject
-    protected SecondaryStorageVmManager _secondaryStorageMgr;
+    private DataCenterDao _dcDao;
     @Inject
-    protected RegionDao _regionDao;
+    private HostPodDao _podDao;
     @Inject
-    protected DataCenterDao _dcDao;
+    private ClusterDetailsDao _clusterDetailsDao;
     @Inject
-    protected HostPodDao _podDao;
+    private ClusterDao _clusterDao;
     @Inject
-    protected ClusterDetailsDao _clusterDetailsDao;
+    private CapacityDao _capacityDao;
     @Inject
-    protected ClusterDao _clusterDao;
+    private HostDao _hostDao;
     @Inject
-    protected CapacityDao _capacityDao;
+    private HostDetailsDao _hostDetailsDao;
     @Inject
-    protected HostDao _hostDao;
+    private ConfigurationDao _configDao;
     @Inject
-    protected HostDetailsDao _hostDetailsDao;
+    private HostTagsDao _hostTagsDao;
     @Inject
-    protected ConfigurationDao _configDao;
+    private GuestOSCategoryDao _guestOSCategoryDao;
     @Inject
-    protected HostTagsDao _hostTagsDao;
+    private PrimaryDataStoreDao _storagePoolDao;
     @Inject
-    protected GuestOSCategoryDao _guestOSCategoryDao;
+    private DataCenterIpAddressDao _privateIPAddressDao;
     @Inject
-    protected PrimaryDataStoreDao _storagePoolDao;
+    private IPAddressDao _publicIPAddressDao;
     @Inject
-    protected DataCenterIpAddressDao _privateIPAddressDao;
+    private VirtualMachineManager _vmMgr;
     @Inject
-    protected IPAddressDao _publicIPAddressDao;
+    private VMInstanceDao _vmDao;
     @Inject
-    protected VirtualMachineManager _vmMgr;
+    private HighAvailabilityManager _haMgr;
     @Inject
-    protected VMInstanceDao _vmDao;
-    @Inject
-    protected HighAvailabilityManager _haMgr;
-    @Inject
-    protected StorageService _storageSvr;
+    private StorageService _storageSvr;
     @Inject
     PlannerHostReservationDao _plannerHostReserveDao;
     @Inject
-    protected DedicatedResourceDao _dedicatedDao;
+    private DedicatedResourceDao _dedicatedDao;
 
-    protected List<? extends Discoverer> _discoverers;
+    private List<? extends Discoverer> _discoverers;
 
     public List<? extends Discoverer> getDiscoverers() {
         return _discoverers;
@@ -227,22 +221,22 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
     }
 
     @Inject
-    protected ClusterManager _clusterMgr;
+    private ClusterManager _clusterMgr;
     @Inject
-    protected StoragePoolHostDao _storagePoolHostDao;
+    private StoragePoolHostDao _storagePoolHostDao;
 
     @Inject
-    protected VMTemplateDao _templateDao;
+    private VMTemplateDao _templateDao;
     @Inject
-    protected ConfigurationManager _configMgr;
+    private ConfigurationManager _configMgr;
     @Inject
-    protected ClusterVSMMapDao _clusterVSMMapDao;
+    private ClusterVSMMapDao _clusterVSMMapDao;
 
-    protected long _nodeId = ManagementServerNode.getManagementServerId();
+    private final long _nodeId = ManagementServerNode.getManagementServerId();
 
-    protected HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<String, ResourceStateAdapter>();
+    private final HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<String, ResourceStateAdapter>();
 
-    protected HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>();
+    private final HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>();
     private HypervisorType _defaultSystemVMHypervisor;
 
     private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/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 9dc9dda..ec40411 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -40,6 +40,9 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -438,7 +441,6 @@ import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
-import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -450,8 +452,6 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.GetVncPortAnswer;
@@ -468,7 +468,6 @@ import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity;
 import com.cloud.cluster.ClusterManager;
 import com.cloud.configuration.Config;
-import com.cloud.configuration.ConfigurationManager;
 import com.cloud.consoleproxy.ConsoleProxyManagementState;
 import com.cloud.consoleproxy.ConsoleProxyManager;
 import com.cloud.dc.AccountVlanMapVO;
@@ -553,7 +552,6 @@ import com.cloud.storage.dao.GuestOSDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
-import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.tags.ResourceTagVO;
 import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.template.TemplateManager;
@@ -699,38 +697,28 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
     private ImageStoreDao _imgStoreDao;
 
     @Inject
-    ProjectManager _projectMgr;
-    @Inject
-    ResourceManager _resourceMgr;
-    @Inject
-    SnapshotManager _snapshotMgr;
-    @Inject
-    HighAvailabilityManager _haMgr;
-    @Inject
-    TemplateManager templateMgr;
-    @Inject
-    DataStoreManager dataStoreMgr;
+    private ProjectManager _projectMgr;
     @Inject
-    HostTagsDao _hostTagsDao;
+    private ResourceManager _resourceMgr;
     @Inject
-    ConfigurationServer _configServer;
+    private HighAvailabilityManager _haMgr;
     @Inject
-    ConfigDepot _configDepot;
+    private DataStoreManager dataStoreMgr;
     @Inject
-    UserVmManager _userVmMgr;
+    private HostTagsDao _hostTagsDao;
     @Inject
-    VolumeDataFactory _volFactory;
+    private ConfigDepot _configDepot;
     @Inject
-    AccountService _accountService;
+    private UserVmManager _userVmMgr;
     @Inject
-    ConfigurationManager _configMgr;
+    private AccountService _accountService;
     @Inject
-    ServiceOfferingDao _offeringDao;
+    private ServiceOfferingDao _offeringDao;
 
     @Inject
-    DeploymentPlanningManager _dpMgr;
+    private DeploymentPlanningManager _dpMgr;
 
-    LockMasterListener _lockMasterListener;
+    private LockMasterListener _lockMasterListener;
 
     private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker"));
     private final ScheduledExecutorService _alertExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AlertChecker"));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index d4fa8c1..252d925 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -26,6 +26,8 @@ import java.util.concurrent.ExecutionException;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
 import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
 import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
@@ -38,14 +40,10 @@ import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationSer
 import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
-import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
-import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
-import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
@@ -68,37 +66,27 @@ import org.apache.cloudstack.storage.command.DettachCommand;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.to.DataTO;
 import com.cloud.agent.api.to.DiskTO;
-import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
-import com.cloud.capacity.CapacityManager;
-import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.Resource.ResourceType;
-import com.cloud.consoleproxy.ConsoleProxyManager;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.dc.dao.HostPodDao;
 import com.cloud.domain.Domain;
-import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
-import com.cloud.event.dao.EventDao;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
@@ -108,29 +96,15 @@ import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.HypervisorCapabilitiesVO;
-import com.cloud.hypervisor.HypervisorGuruManager;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
-import com.cloud.network.NetworkModel;
 import com.cloud.org.Grouping;
-import com.cloud.resource.ResourceManager;
-import com.cloud.server.ManagementServer;
-import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
-import com.cloud.storage.dao.SnapshotPolicyDao;
-import com.cloud.storage.dao.StoragePoolHostDao;
-import com.cloud.storage.dao.StoragePoolWorkDao;
 import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplatePoolDao;
 import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.dao.VolumeDetailsDao;
-import com.cloud.storage.download.DownloadMonitor;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.snapshot.SnapshotApiService;
 import com.cloud.storage.snapshot.SnapshotManager;
-import com.cloud.storage.snapshot.SnapshotScheduler;
-import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.template.TemplateManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
@@ -138,7 +112,6 @@ import com.cloud.user.ResourceLimitService;
 import com.cloud.user.User;
 import com.cloud.user.VmDiskStatisticsVO;
 import com.cloud.user.dao.AccountDao;
-import com.cloud.user.dao.UserDao;
 import com.cloud.user.dao.VmDiskStatisticsDao;
 import com.cloud.utils.EnumUtils;
 import com.cloud.utils.NumbersUtil;
@@ -155,20 +128,15 @@ import com.cloud.utils.db.UUIDManager;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.utils.fsm.StateMachine2;
-import com.cloud.vm.UserVmManager;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VmWork;
 import com.cloud.vm.VmWorkConstants;
 import com.cloud.vm.VmWorkJobHandler;
 import com.cloud.vm.VmWorkJobHandlerProxy;
 import com.cloud.vm.VmWorkSerializer;
-import com.cloud.vm.dao.ConsoleProxyDao;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.SecondaryStorageVmDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDao;
 import com.cloud.vm.snapshot.VMSnapshotVO;
@@ -180,153 +148,73 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
     public static final String VM_WORK_JOB_HANDLER = VolumeApiServiceImpl.class.getSimpleName();
 
     @Inject
-    VolumeOrchestrationService _volumeMgr;
+    private VolumeOrchestrationService _volumeMgr;
 
     @Inject
-    EntityManager _entityMgr;
-    @Inject
-    protected UserVmManager _userVmMgr;
-    @Inject
-    protected AgentManager _agentMgr;
-    @Inject
-    protected TemplateManager _tmpltMgr;
-    @Inject
-    protected AsyncJobManager _asyncMgr;
-    @Inject
-    protected SnapshotManager _snapshotMgr;
-    @Inject
-    protected SnapshotScheduler _snapshotScheduler;
-    @Inject
-    protected AccountManager _accountMgr;
-    @Inject
-    protected ConfigurationManager _configMgr;
+    private EntityManager _entityMgr;
     @Inject
-    protected ConsoleProxyManager _consoleProxyMgr;
+    private AgentManager _agentMgr;
     @Inject
-    protected SecondaryStorageVmManager _secStorageMgr;
+    private TemplateManager _tmpltMgr;
     @Inject
-    protected NetworkModel _networkMgr;
+    private AsyncJobManager _asyncMgr;
     @Inject
-    protected ServiceOfferingDao _serviceOfferingDao;
+    private SnapshotManager _snapshotMgr;
     @Inject
-    protected VolumeDao _volsDao;
+    private AccountManager _accountMgr;
     @Inject
-    protected HostDao _hostDao;
+    private ConfigurationManager _configMgr;
     @Inject
-    protected ConsoleProxyDao _consoleProxyDao;
+    private VolumeDao _volsDao;
     @Inject
-    protected SnapshotDao _snapshotDao;
+    private HostDao _hostDao;
     @Inject
-    protected SnapshotManager _snapMgr;
-    @Inject
-    protected SnapshotPolicyDao _snapshotPolicyDao;
-    @Inject
-    protected StoragePoolHostDao _storagePoolHostDao;
+    private SnapshotDao _snapshotDao;
     @Inject
     StoragePoolDetailsDao storagePoolDetailsDao;
     @Inject
-    protected AlertManager _alertMgr;
-    @Inject
-    protected TemplateDataStoreDao _vmTemplateStoreDao = null;
-    @Inject
-    protected VMTemplatePoolDao _vmTemplatePoolDao = null;
-    @Inject
-    protected VMTemplateDao _vmTemplateDao = null;
-    @Inject
-    protected StoragePoolHostDao _poolHostDao = null;
-    @Inject
-    protected UserVmDao _userVmDao;
+    private UserVmDao _userVmDao;
     @Inject
     VolumeDataStoreDao _volumeStoreDao;
     @Inject
-    protected VMInstanceDao _vmInstanceDao;
-    @Inject
-    protected PrimaryDataStoreDao _storagePoolDao = null;
-    @Inject
-    protected CapacityDao _capacityDao;
-    @Inject
-    protected CapacityManager _capacityMgr;
-    @Inject
-    protected DiskOfferingDao _diskOfferingDao;
+    private VMInstanceDao _vmInstanceDao;
     @Inject
-    protected AccountDao _accountDao;
+    private final PrimaryDataStoreDao _storagePoolDao = null;
     @Inject
-    protected EventDao _eventDao = null;
+    private DiskOfferingDao _diskOfferingDao;
     @Inject
-    protected DataCenterDao _dcDao = null;
+    private AccountDao _accountDao;
     @Inject
-    protected HostPodDao _podDao = null;
+    private final DataCenterDao _dcDao = null;
     @Inject
-    protected VMTemplateDao _templateDao;
+    private VMTemplateDao _templateDao;
     @Inject
-    protected ServiceOfferingDao _offeringDao;
+    private VolumeDao _volumeDao;
     @Inject
-    protected DomainDao _domainDao;
+    private ResourceLimitService _resourceLimitMgr;
     @Inject
-    protected UserDao _userDao;
+    private VmDiskStatisticsDao _vmDiskStatsDao;
     @Inject
-    protected ClusterDao _clusterDao;
+    private VMSnapshotDao _vmSnapshotDao;
+    private List<StoragePoolAllocator> _storagePoolAllocators;
     @Inject
-    protected VirtualMachineManager _vmMgr;
+    private ConfigurationDao _configDao;
     @Inject
-    protected DomainRouterDao _domrDao;
+    private DataStoreManager dataStoreMgr;
     @Inject
-    protected SecondaryStorageVmDao _secStrgDao;
+    private VolumeService volService;
     @Inject
-    protected StoragePoolWorkDao _storagePoolWorkDao;
+    private VolumeDataFactory volFactory;
     @Inject
-    protected HypervisorGuruManager _hvGuruMgr;
+    private SnapshotApiService snapshotMgr;
     @Inject
-    protected VolumeDao _volumeDao;
-    @Inject
-    protected OCFS2Manager _ocfs2Mgr;
-    @Inject
-    protected ResourceLimitService _resourceLimitMgr;
-    @Inject
-    protected SecondaryStorageVmManager _ssvmMgr;
-    @Inject
-    protected ResourceManager _resourceMgr;
-    @Inject
-    protected DownloadMonitor _downloadMonitor;
-    @Inject
-    protected ResourceTagDao _resourceTagDao;
-    @Inject
-    protected VmDiskStatisticsDao _vmDiskStatsDao;
-    @Inject
-    protected VMSnapshotDao _vmSnapshotDao;
-    protected List<StoragePoolAllocator> _storagePoolAllocators;
-    @Inject
-    ConfigurationDao _configDao;
-    @Inject
-    VolumeDetailsDao _volDetailDao;
-    @Inject
-    ManagementServer _msServer;
-    @Inject
-    DataStoreManager dataStoreMgr;
-    @Inject
-    DataStoreProviderManager dataStoreProviderMgr;
-    @Inject
-    VolumeService volService;
-    @Inject
-    VolumeDataFactory volFactory;
-    @Inject
-    TemplateDataFactory tmplFactory;
-    @Inject
-    SnapshotDataFactory snapshotFactory;
-    @Inject
-    SnapshotApiService snapshotMgr;
-    @Inject
-    SnapshotService snapshotSrv;
-    @Inject
-    UUIDManager _uuidMgr;
+    private UUIDManager _uuidMgr;
 
     @Inject
-    protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
-    @Inject
-    StorageManager storageMgr;
+    private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
 
     @Inject
-    protected AsyncJobManager _jobMgr;
+    private AsyncJobManager _jobMgr;
 
     @Inject
     protected VmWorkJobDao _workJobDao;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
index 33278af..1b44a12 100755
--- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
+++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
@@ -31,10 +31,8 @@ import org.springframework.stereotype.Component;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
-import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -42,7 +40,6 @@ import org.apache.cloudstack.storage.command.DownloadCommand;
 import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
 import org.apache.cloudstack.storage.command.DownloadProgressCommand;
 import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@@ -60,7 +57,6 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.storage.Volume;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.template.TemplateConstants;
 import com.cloud.storage.upload.UploadListener;
 import com.cloud.template.VirtualMachineTemplate;
@@ -74,39 +70,28 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
     static final Logger s_logger = Logger.getLogger(DownloadMonitorImpl.class);
 
     @Inject
-    TemplateDataStoreDao _vmTemplateStoreDao;
+    private TemplateDataStoreDao _vmTemplateStoreDao;
     @Inject
-    ImageStoreDao _imageStoreDao;
+    private VolumeDao _volumeDao;
     @Inject
-    VolumeDao _volumeDao;
+    private VolumeDataStoreDao _volumeStoreDao;
     @Inject
-    VolumeDataStoreDao _volumeStoreDao;
-    @Inject
-    VMTemplateDao _templateDao = null;
+    private final VMTemplateDao _templateDao = null;
     @Inject
     private AgentManager _agentMgr;
     @Inject
-    SecondaryStorageVmManager _secMgr;
-    @Inject
-    ConfigurationDao _configDao;
-    @Inject
-    EndPointSelector _epSelector;
+    private ConfigurationDao _configDao;
     @Inject
-    TemplateDataFactory tmplFactory;
+    private EndPointSelector _epSelector;
 
-    private Boolean _sslCopy = new Boolean(false);
     private String _copyAuthPasswd;
     private String _proxy = null;
 
-    Timer _timer;
-
-    @Inject
-    DataStoreManager storeMgr;
+    private Timer _timer;
 
     @Override
     public boolean configure(String name, Map<String, Object> params) {
         final Map<String, String> configs = _configDao.getConfiguration("management-server", params);
-        _sslCopy = Boolean.parseBoolean(configs.get("secstorage.encrypt.copy"));
         _proxy = configs.get(Config.SecStorageProxy.key());
 
         String cert = configs.get("secstorage.ssl.cert.domain");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/secondary/SecondaryStorageListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageListener.java b/server/src/com/cloud/storage/secondary/SecondaryStorageListener.java
index 4215fa6..43613e7 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageListener.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageListener.java
@@ -18,7 +18,6 @@ package com.cloud.storage.secondary;
 
 import org.apache.log4j.Logger;
 
-import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
 import com.cloud.agent.api.AgentControlAnswer;
 import com.cloud.agent.api.AgentControlCommand;
@@ -35,11 +34,9 @@ public class SecondaryStorageListener implements Listener {
     private final static Logger s_logger = Logger.getLogger(SecondaryStorageListener.class);
 
     SecondaryStorageVmManager _ssVmMgr = null;
-    AgentManager _agentMgr = null;
 
-    public SecondaryStorageListener(SecondaryStorageVmManager ssVmMgr, AgentManager agentMgr) {
+    public SecondaryStorageListener(SecondaryStorageVmManager ssVmMgr) {
         _ssVmMgr = ssVmMgr;
-        _agentMgr = agentMgr;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index a5d3d4c..484dfbd 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -211,8 +211,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
     UserVmDetailsDao _vmDetailsDao;
     @Inject
     protected ResourceManager _resourceMgr;
-    //@Inject            // TODO this is a very strange usage, a singleton class need to inject itself?
-    protected SecondaryStorageVmManager _ssvmMgr;
     @Inject
     NetworkDao _networkDao;
     @Inject
@@ -250,7 +248,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
     private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName());
 
     public SecondaryStorageManagerImpl() {
-        _ssvmMgr = this;
     }
 
     @Override
@@ -825,7 +822,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
         value = agentMgrConfigs.get("port");
         _mgmtPort = NumbersUtil.parseInt(value, 8250);
 
-        _listener = new SecondaryStorageListener(this, _agentMgr);
+        _listener = new SecondaryStorageListener(this);
         _agentMgr.registerForHostEvents(_listener, true, false, true);
 
         _itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index a9eae7d..821f43a 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -34,7 +34,6 @@ import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd
 import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
 import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
 import org.apache.cloudstack.context.CallContext;
-import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -54,7 +53,6 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 
-import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.DeleteSnapshotsDirCommand;
@@ -64,7 +62,6 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.dao.ClusterDao;
-import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.ActionEventUtils;
@@ -94,17 +91,14 @@ import com.cloud.storage.StoragePool;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.SnapshotPolicyDao;
 import com.cloud.storage.dao.SnapshotScheduleDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.template.TemplateConstants;
 import com.cloud.tags.ResourceTagVO;
 import com.cloud.tags.dao.ResourceTagDao;
-import com.cloud.template.TemplateManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
@@ -138,46 +132,38 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, SnapshotApiService {
     private static final Logger s_logger = Logger.getLogger(SnapshotManagerImpl.class);
     @Inject
-    protected VMTemplateDao _templateDao;
+    private VMTemplateDao _templateDao;
     @Inject
-    protected UserVmDao _vmDao;
+    private UserVmDao _vmDao;
     @Inject
-    protected VolumeDao _volsDao;
+    private VolumeDao _volsDao;
     @Inject
-    protected AccountDao _accountDao;
+    private AccountDao _accountDao;
     @Inject
-    protected DataCenterDao _dcDao;
+    private SnapshotDao _snapshotDao;
     @Inject
-    protected DiskOfferingDao _diskOfferingDao;
+    private SnapshotDataStoreDao _snapshotStoreDao;
     @Inject
-    protected SnapshotDao _snapshotDao;
+    private PrimaryDataStoreDao _storagePoolDao;
     @Inject
-    protected SnapshotDataStoreDao _snapshotStoreDao;
+    private final SnapshotPolicyDao _snapshotPolicyDao = null;
     @Inject
-    protected PrimaryDataStoreDao _storagePoolDao;
+    private SnapshotScheduleDao _snapshotScheduleDao;
     @Inject
-    protected SnapshotPolicyDao _snapshotPolicyDao = null;
+    private DomainDao _domainDao;
     @Inject
-    protected SnapshotScheduleDao _snapshotScheduleDao;
+    private StorageManager _storageMgr;
     @Inject
-    protected DomainDao _domainDao;
+    private SnapshotScheduler _snapSchedMgr;
     @Inject
-    protected StorageManager _storageMgr;
-    @Inject
-    protected AgentManager _agentMgr;
-    @Inject
-    protected SnapshotScheduler _snapSchedMgr;
-    @Inject
-    protected AccountManager _accountMgr;
+    private AccountManager _accountMgr;
     @Inject
     private AlertManager _alertMgr;
     @Inject
-    protected ClusterDao _clusterDao;
+    private ClusterDao _clusterDao;
     @Inject
     private ResourceLimitService _resourceLimitMgr;
     @Inject
-    private SecondaryStorageVmManager _ssvmMgr;
-    @Inject
     private DomainManager _domainMgr;
     @Inject
     private ResourceTagDao _resourceTagDao;
@@ -185,33 +171,23 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
     private ConfigurationDao _configDao;
     @Inject
     private VMSnapshotDao _vmSnapshotDao;
-    String _name;
     @Inject
-    TemplateManager templateMgr;
+    private DataStoreManager dataStoreMgr;
     @Inject
-    VolumeOrchestrationService volumeMgr;
+    private SnapshotService snapshotSrv;
     @Inject
-    DataStoreManager dataStoreMgr;
+    private VolumeDataFactory volFactory;
     @Inject
-    SnapshotService snapshotSrv;
+    private SnapshotDataFactory snapshotFactory;
     @Inject
-    VolumeDataFactory volFactory;
-    @Inject
-    SnapshotDataFactory snapshotFactory;
-    @Inject
-    EndPointSelector _epSelector;
+    private EndPointSelector _epSelector;
     @Inject
     private ResourceManager _resourceMgr;
     @Inject
-    StorageStrategyFactory _storageStrategyFactory;
+    private StorageStrategyFactory _storageStrategyFactory;
 
     private int _totalRetries;
     private int _pauseInterval;
-    private int _backupsnapshotwait;
-    Boolean backup;
-
-    protected SearchBuilder<SnapshotVO> PolicySnapshotSearch;
-    protected SearchBuilder<SnapshotPolicyVO> PoliciesForSnapSearch;
 
     @Override
     public Answer sendToPool(Volume vol, Command cmd) {
@@ -970,8 +946,6 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
 
         String value = _configDao.getValue(Config.BackupSnapshotWait.toString());
-        _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
-        backup = Boolean.parseBoolean(_configDao.getValue(Config.BackupSnapshotAfterTakingSnapshot.toString()));
 
         Type.HOURLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.hourly"), HOURLYMAX));
         Type.DAILY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.daily"), DAILYMAX));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
index 6f1f5e9..8a997b2 100755
--- a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
+++ b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java
@@ -67,8 +67,6 @@ import com.cloud.storage.UploadVO;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.UploadDao;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -89,35 +87,30 @@ public class UploadMonitorImpl extends ManagerBase implements UploadMonitor {
     static final Logger s_logger = Logger.getLogger(UploadMonitorImpl.class);
 
     @Inject
-    UploadDao _uploadDao;
+    private UploadDao _uploadDao;
     @Inject
-    SecondaryStorageVmDao _secStorageVmDao;
+    private SecondaryStorageVmDao _secStorageVmDao;
 
     @Inject
-    HostDao _serverDao = null;
-    @Inject
-    VMTemplateDao _templateDao = null;
+    private final HostDao _serverDao = null;
     @Inject
     private AgentManager _agentMgr;
     @Inject
-    ConfigurationDao _configDao;
-    @Inject
-    ResourceManager _resourceMgr;
+    private ConfigurationDao _configDao;
     @Inject
-    SecondaryStorageVmManager _ssvmMgr;
+    private ResourceManager _resourceMgr;
     @Inject
-    EndPointSelector _epSelector;
+    private EndPointSelector _epSelector;
     @Inject
-    DataStoreManager storeMgr;
+    private DataStoreManager storeMgr;
 
-    private String _name;
     private Boolean _sslCopy = new Boolean(false);
     private String _ssvmUrlDomain;
     private ScheduledExecutorService _executor = null;
 
-    Timer _timer;
-    int _cleanupInterval;
-    int _urlExpirationInterval;
+    private Timer _timer;
+    private int _cleanupInterval;
+    private int _urlExpirationInterval;
 
     final Map<UploadVO, UploadListener> _listenerMap = new ConcurrentHashMap<UploadVO, UploadListener>();
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 93e3c59..70e4a49 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -72,12 +72,10 @@ import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.command.AttachCommand;
 import org.apache.cloudstack.storage.command.CommandResult;
 import org.apache.cloudstack.storage.command.DettachCommand;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
@@ -99,7 +97,6 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.domain.Domain;
 import com.cloud.domain.dao.DomainDao;
@@ -107,7 +104,6 @@ import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.event.UsageEventVO;
-import com.cloud.event.dao.EventDao;
 import com.cloud.event.dao.UsageEventDao;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
@@ -117,11 +113,8 @@ import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.hypervisor.HypervisorGuruManager;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectManager;
-import com.cloud.resource.ResourceManager;
-import com.cloud.server.ConfigurationServer;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.GuestOSVO;
 import com.cloud.storage.LaunchPermissionVO;
@@ -148,16 +141,10 @@ import com.cloud.storage.dao.GuestOSDao;
 import com.cloud.storage.dao.LaunchPermissionDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.StoragePoolHostDao;
-import com.cloud.storage.dao.UploadDao;
 import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplateDetailsDao;
-import com.cloud.storage.dao.VMTemplateHostDao;
 import com.cloud.storage.dao.VMTemplatePoolDao;
 import com.cloud.storage.dao.VMTemplateZoneDao;
 import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.download.DownloadMonitor;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
-import com.cloud.storage.upload.UploadMonitor;
 import com.cloud.template.TemplateAdapter.TemplateAdapterType;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
@@ -166,11 +153,8 @@ import com.cloud.user.AccountVO;
 import com.cloud.user.ResourceLimitService;
 import com.cloud.user.User;
 import com.cloud.user.dao.AccountDao;
-import com.cloud.user.dao.UserAccountDao;
-import com.cloud.user.dao.UserDao;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.EnumUtils;
-import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.ManagerBase;
@@ -180,12 +164,10 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.TransactionCallbackNoReturn;
 import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.UserVmManager;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
-import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = {TemplateManager.class, TemplateApiService.class})
@@ -193,116 +175,78 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class);
 
     @Inject
-    VMTemplateDao _tmpltDao;
+    private VMTemplateDao _tmpltDao;
     @Inject
-    TemplateDataStoreDao _tmplStoreDao;
+    private TemplateDataStoreDao _tmplStoreDao;
     @Inject
-    VMTemplatePoolDao _tmpltPoolDao;
+    private VMTemplatePoolDao _tmpltPoolDao;
     @Inject
-    VMTemplateZoneDao _tmpltZoneDao;
+    private VMTemplateZoneDao _tmpltZoneDao;
     @Inject
-    protected UserVmDetailsDao _vmDetailsDao;
+    private VMInstanceDao _vmInstanceDao;
     @Inject
-    protected VMTemplateDetailsDao _templateDetailsDao;
+    private PrimaryDataStoreDao _poolDao;
     @Inject
-    VMInstanceDao _vmInstanceDao;
+    private StoragePoolHostDao _poolHostDao;
     @Inject
-    PrimaryDataStoreDao _poolDao;
+    private AccountDao _accountDao;
     @Inject
-    StoragePoolHostDao _poolHostDao;
+    private AgentManager _agentMgr;
     @Inject
-    EventDao _eventDao;
+    private AccountManager _accountMgr;
     @Inject
-    DownloadMonitor _downloadMonitor;
+    private HostDao _hostDao;
     @Inject
-    UploadMonitor _uploadMonitor;
+    private DataCenterDao _dcDao;
     @Inject
-    UserAccountDao _userAccountDao;
+    private UserVmDao _userVmDao;
     @Inject
-    AccountDao _accountDao;
+    private VolumeDao _volumeDao;
     @Inject
-    UserDao _userDao;
+    private SnapshotDao _snapshotDao;
     @Inject
-    AgentManager _agentMgr;
+    private ConfigurationDao _configDao;
     @Inject
-    AccountManager _accountMgr;
+    private DomainDao _domainDao;
     @Inject
-    HostDao _hostDao;
+    private GuestOSDao _guestOSDao;
     @Inject
-    DataCenterDao _dcDao;
+    private StorageManager _storageMgr;
     @Inject
-    UserVmDao _userVmDao;
+    private UsageEventDao _usageEventDao;
     @Inject
-    VolumeDao _volumeDao;
+    private AccountService _accountService;
     @Inject
-    SnapshotDao _snapshotDao;
+    private ResourceLimitService _resourceLimitMgr;
     @Inject
-    ConfigurationDao _configDao;
+    private LaunchPermissionDao _launchPermissionDao;
     @Inject
-    ClusterDao _clusterDao;
+    private ProjectManager _projectMgr;
     @Inject
-    DomainDao _domainDao;
+    private VolumeDataFactory _volFactory;
     @Inject
-    UploadDao _uploadDao;
+    private TemplateDataFactory _tmplFactory;
     @Inject
-    protected GuestOSDao _guestOSDao;
+    private SnapshotDataFactory _snapshotFactory;
     @Inject
-    StorageManager _storageMgr;
+    private TemplateService _tmpltSvr;
     @Inject
-    AsyncJobManager _asyncMgr;
+    private DataStoreManager _dataStoreMgr;
     @Inject
-    UserVmManager _vmMgr;
+    private VolumeOrchestrationService _volumeMgr;
     @Inject
-    UsageEventDao _usageEventDao;
+    private EndPointSelector _epSelector;
     @Inject
-    HypervisorGuruManager _hvGuruMgr;
-    @Inject
-    AccountService _accountService;
-    @Inject
-    ResourceLimitService _resourceLimitMgr;
-    @Inject
-    SecondaryStorageVmManager _ssvmMgr;
-    @Inject
-    LaunchPermissionDao _launchPermissionDao;
-    @Inject
-    ProjectManager _projectMgr;
-    @Inject
-    VolumeDataFactory _volFactory;
-    @Inject
-    TemplateDataFactory _tmplFactory;
-    @Inject
-    SnapshotDataFactory _snapshotFactory;
-    @Inject
-    TemplateService _tmpltSvr;
-    @Inject
-    DataStoreManager _dataStoreMgr;
-    @Inject
-    protected ResourceManager _resourceMgr;
-    @Inject
-    VolumeOrchestrationService _volumeMgr;
-    @Inject
-    ImageStoreDao _imageStoreDao;
-    @Inject
-    EndPointSelector _epSelector;
-    @Inject
-    UserVmJoinDao _userVmJoinDao;
-    @Inject
-    VMTemplateHostDao _vmTemplateHostDao;
-
-    @Inject
-    ConfigurationServer _configServer;
-
-    int _primaryStorageDownloadWait;
-    int _storagePoolMaxWaitSeconds = 3600;
-    boolean _disableExtraction = false;
-    ExecutorService _preloadExecutor;
+    private UserVmJoinDao _userVmJoinDao;
+    private boolean _disableExtraction = false;
+    private ExecutorService _preloadExecutor;
 
-    protected List<TemplateAdapter> _adapters;
+    private List<TemplateAdapter> _adapters;
 
     @Inject
-    StorageCacheManager cacheMgr;
+    private StorageCacheManager cacheMgr;
     @Inject
-    EndPointSelector selector;
+    private EndPointSelector selector;
 
     private TemplateAdapter getAdapter(HypervisorType type) {
         TemplateAdapter adapter = null;
@@ -842,13 +786,10 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
-        _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
 
         String disableExtraction = _configDao.getValue(Config.DisableExtraction.toString());
         _disableExtraction = (disableExtraction == null) ? false : Boolean.parseBoolean(disableExtraction);
 
-        _storagePoolMaxWaitSeconds = NumbersUtil.parseInt(_configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
         _preloadExecutor = Executors.newFixedThreadPool(8, new NamedThreadFactory("Template-Preloader"));
 
         return true;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f34282d/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
index 58d02fa..22516c0 100644
--- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
@@ -106,7 +106,6 @@ import com.cloud.storage.dao.DiskOfferingDaoImpl;
 import com.cloud.storage.dao.SnapshotDaoImpl;
 import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
 import com.cloud.storage.dao.VolumeDaoImpl;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.user.AccountDetailsDao;
 import com.cloud.user.AccountManager;
@@ -181,11 +180,6 @@ public class ChildTestConfiguration {
     }
 
     @Bean
-    public SecondaryStorageVmManager ssvmMgr() {
-        return Mockito.mock(SecondaryStorageVmManager.class);
-    }
-
-    @Bean
     public VpcManager vpcMgr() {
         return Mockito.mock(VpcManager.class);
     }


[05/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
new file mode 100755
index 0000000..cdbc52d
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
@@ -0,0 +1,550 @@
+// 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.storage.template;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
+
+import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
+import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
+import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.UploadAnswer;
+import com.cloud.agent.api.storage.UploadCommand;
+import com.cloud.agent.api.storage.UploadProgressCommand;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.StorageLayer;
+import com.cloud.storage.Upload;
+import com.cloud.storage.UploadVO;
+import com.cloud.storage.template.FtpTemplateUploader;
+import com.cloud.storage.template.TemplateUploader;
+import com.cloud.storage.template.TemplateUploader.Status;
+import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+public class UploadManagerImpl extends ManagerBase implements UploadManager {
+
+    public class Completion implements UploadCompleteCallback {
+        private final String jobId;
+
+        public Completion(String jobId) {
+            this.jobId = jobId;
+        }
+
+        @Override
+        public void uploadComplete(Status status) {
+            setUploadStatus(jobId, status);
+        }
+    }
+
+    private static class UploadJob {
+        private final TemplateUploader tu;
+
+        public UploadJob(TemplateUploader tu, String jobId, long id, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+                String installPathPrefix) {
+            super();
+            this.tu = tu;
+        }
+
+        public TemplateUploader getTemplateUploader() {
+            return tu;
+        }
+
+        public void cleanup() {
+            if (tu != null) {
+                String upldPath = tu.getUploadLocalPath();
+                if (upldPath != null) {
+                    File f = new File(upldPath);
+                    f.delete();
+                }
+            }
+        }
+
+    }
+
+    public static final Logger s_logger = Logger.getLogger(UploadManagerImpl.class);
+    private ExecutorService threadPool;
+    private final Map<String, UploadJob> jobs = new ConcurrentHashMap<String, UploadJob>();
+    private String parentDir;
+    private final String extractMountPoint = "/mnt/SecStorage/extractmnt";
+    private StorageLayer _storage;
+    private boolean hvm;
+
+    @Override
+    public String uploadPublicTemplate(long id, String url, String name, ImageFormat format, Long accountId, String descr, String cksum, String installPathPrefix,
+            String userName, String passwd, long templateSizeInBytes) {
+
+        UUID uuid = UUID.randomUUID();
+        String jobId = uuid.toString();
+
+        String completePath = parentDir + File.separator + installPathPrefix;
+        s_logger.debug("Starting upload from " + completePath);
+
+        URI uri;
+        try {
+            uri = new URI(url);
+        } catch (URISyntaxException e) {
+            s_logger.error("URI is incorrect: " + url);
+            throw new CloudRuntimeException("URI is incorrect: " + url);
+        }
+        TemplateUploader tu;
+        if ((uri != null) && (uri.getScheme() != null)) {
+            if (uri.getScheme().equalsIgnoreCase("ftp")) {
+                tu = new FtpTemplateUploader(completePath, url, new Completion(jobId), templateSizeInBytes);
+            } else {
+                s_logger.error("Scheme is not supported " + url);
+                throw new CloudRuntimeException("Scheme is not supported " + url);
+            }
+        } else {
+            s_logger.error("Unable to download from URL: " + url);
+            throw new CloudRuntimeException("Unable to download from URL: " + url);
+        }
+        UploadJob uj = new UploadJob(tu, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix);
+        jobs.put(jobId, uj);
+        threadPool.execute(tu);
+
+        return jobId;
+
+    }
+
+    @Override
+    public String getUploadError(String jobId) {
+        UploadJob uj = jobs.get(jobId);
+        if (uj != null) {
+            return uj.getTemplateUploader().getUploadError();
+        }
+        return null;
+    }
+
+    @Override
+    public int getUploadPct(String jobId) {
+        UploadJob uj = jobs.get(jobId);
+        if (uj != null) {
+            return uj.getTemplateUploader().getUploadPercent();
+        }
+        return 0;
+    }
+
+    @Override
+    public Status getUploadStatus(String jobId) {
+        UploadJob job = jobs.get(jobId);
+        if (job != null) {
+            TemplateUploader tu = job.getTemplateUploader();
+            if (tu != null) {
+                return tu.getStatus();
+            }
+        }
+        return Status.UNKNOWN;
+    }
+
+    public static UploadVO.Status convertStatus(Status tds) {
+        switch (tds) {
+        case ABORTED:
+            return UploadVO.Status.NOT_UPLOADED;
+        case UPLOAD_FINISHED:
+            return UploadVO.Status.UPLOAD_IN_PROGRESS;
+        case IN_PROGRESS:
+            return UploadVO.Status.UPLOAD_IN_PROGRESS;
+        case NOT_STARTED:
+            return UploadVO.Status.NOT_UPLOADED;
+        case RECOVERABLE_ERROR:
+            return UploadVO.Status.NOT_UPLOADED;
+        case UNKNOWN:
+            return UploadVO.Status.UNKNOWN;
+        case UNRECOVERABLE_ERROR:
+            return UploadVO.Status.UPLOAD_ERROR;
+        case POST_UPLOAD_FINISHED:
+            return UploadVO.Status.UPLOADED;
+        default:
+            return UploadVO.Status.UNKNOWN;
+        }
+    }
+
+    @Override
+    public com.cloud.storage.UploadVO.Status getUploadStatus2(String jobId) {
+        return convertStatus(getUploadStatus(jobId));
+    }
+
+    @Override
+    public String getPublicTemplateRepo() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private UploadAnswer handleUploadProgressCmd(UploadProgressCommand cmd) {
+        String jobId = cmd.getJobId();
+        UploadAnswer answer;
+        UploadJob uj = null;
+        if (jobId != null)
+            uj = jobs.get(jobId);
+        if (uj == null) {
+            return new UploadAnswer(null, 0, "Cannot find job", com.cloud.storage.UploadVO.Status.UNKNOWN, "", "", 0);
+        }
+        TemplateUploader td = uj.getTemplateUploader();
+        switch (cmd.getRequest()) {
+        case GET_STATUS:
+            break;
+        case ABORT:
+            td.stopUpload();
+            sleep();
+            break;
+            /*case RESTART:
+            td.stopUpload();
+            sleep();
+            threadPool.execute(td);
+            break;*/
+        case PURGE:
+            td.stopUpload();
+            answer =
+                    new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
+                            getUploadTemplateSize(jobId));
+            jobs.remove(jobId);
+            return answer;
+        default:
+            break; // TODO
+        }
+        return new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
+                getUploadTemplateSize(jobId));
+    }
+
+    @Override
+    public UploadAnswer handleUploadCommand(SecondaryStorageResource resource, UploadCommand cmd) {
+        s_logger.warn("Handling the upload " + cmd.getInstallPath() + " " + cmd.getId());
+        if (cmd instanceof UploadProgressCommand) {
+            return handleUploadProgressCmd((UploadProgressCommand)cmd);
+        }
+
+        String user = null;
+        String password = null;
+        String jobId =
+                uploadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(),
+                        cmd.getInstallPath(), user, password, cmd.getTemplateSizeInBytes());
+        sleep();
+        return new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
+                getUploadTemplateSize(jobId));
+    }
+
+    @Override
+    public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd) {
+
+        boolean isApacheUp = checkAndStartApache();
+        if (!isApacheUp) {
+            String errorString = "Error in starting Apache server ";
+            s_logger.error(errorString);
+            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+        }
+        // Create the directory structure so that its visible under apache server root
+        String extractDir = "/var/www/html/userdata/";
+        Script command = new Script("mkdir", s_logger);
+        command.add("-p");
+        command.add(extractDir);
+        String result = command.execute();
+        if (result != null) {
+            String errorString = "Error in creating directory =" + result;
+            s_logger.error(errorString);
+            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+        }
+
+        // Create a random file under the directory for security reasons.
+        String uuid = cmd.getExtractLinkUUID();
+        command = new Script("touch", s_logger);
+        command.add(extractDir + uuid);
+        result = command.execute();
+        if (result != null) {
+            String errorString = "Error in creating file " + uuid + " ,error: " + result;
+            s_logger.warn(errorString);
+            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+        }
+
+        // Create a symbolic link from the actual directory to the template location. The entity would be directly visible under /var/www/html/userdata/cmd.getInstallPath();
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("ln -sf /mnt/SecStorage/" + cmd.getParent() + File.separator + cmd.getInstallPath() + " " + extractDir + uuid);
+        result = command.execute();
+        if (result != null) {
+            String errorString = "Error in linking  err=" + result;
+            s_logger.error(errorString);
+            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+        }
+
+        return new CreateEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
+
+    }
+
+    @Override
+    public DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd) {
+
+        //Delete the soft link. Example path = volumes/8/74eeb2c6-8ab1-4357-841f-2e9d06d1f360.vhd
+        s_logger.warn("handleDeleteEntityDownloadURLCommand Path:" + cmd.getPath() + " Type:" + cmd.getType().toString());
+        String path = cmd.getPath();
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+
+        //We just need to remove the UUID.vhd
+        String extractUrl = cmd.getExtractUrl();
+        command.add("unlink /var/www/html/userdata/" + extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1));
+        String result = command.execute();
+        if (result != null) {
+            String errorString = "Error in deleting =" + result;
+            s_logger.warn(errorString);
+            return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+        }
+
+        // If its a volume also delete the Hard link since it was created only for the purpose of download.
+        if (cmd.getType() == Upload.Type.VOLUME) {
+            command = new Script("/bin/bash", s_logger);
+            command.add("-c");
+            command.add("rm -f /mnt/SecStorage/" + cmd.getParentPath() + File.separator + path);
+            s_logger.warn(" " + parentDir + File.separator + path);
+            result = command.execute();
+            if (result != null) {
+                String errorString = "Error in linking  err=" + result;
+                s_logger.warn(errorString);
+                return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
+            }
+        }
+
+        return new DeleteEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
+    }
+
+    private String getInstallPath(String jobId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private String getUploadLocalPath(String jobId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private long getUploadTemplateSize(String jobId) {
+        return 0;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+
+        String value = null;
+
+        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
+        if (_storage == null) {
+            value = (String)params.get(StorageLayer.ClassConfigKey);
+            if (value == null) {
+                throw new ConfigurationException("Unable to find the storage layer");
+            }
+
+            Class<StorageLayer> clazz;
+            try {
+                clazz = (Class<StorageLayer>)Class.forName(value);
+                _storage = clazz.newInstance();
+            } catch (ClassNotFoundException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (InstantiationException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (IllegalAccessException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            }
+        }
+
+        String inSystemVM = (String)params.get("secondary.storage.vm");
+        if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
+            s_logger.info("UploadManager: starting additional services since we are inside system vm");
+            startAdditionalServices();
+            //blockOutgoingOnPrivate();
+        }
+
+        value = (String)params.get("install.numthreads");
+        final int numInstallThreads = NumbersUtil.parseInt(value, 10);
+
+        String scriptsDir = (String)params.get("template.scripts.dir");
+        if (scriptsDir == null) {
+            scriptsDir = "scripts/storage/secondary";
+        }
+
+        // Add more processors here.
+        threadPool = Executors.newFixedThreadPool(numInstallThreads);
+
+        return true;
+    }
+
+    private void startAdditionalServices() {
+
+        Script command = new Script("rm", s_logger);
+        command.add("-rf");
+        command.add(extractMountPoint);
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in creating file " + extractMountPoint + " ,error: " + result);
+            return;
+        }
+
+        command = new Script("touch", s_logger);
+        command.add(extractMountPoint);
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in creating file " + extractMountPoint + " ,error: " + result);
+            return;
+        }
+
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("ln -sf " + parentDir + " " + extractMountPoint);
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in linking  err=" + result);
+            return;
+        }
+
+    }
+
+    /**
+     * Get notified of change of job status. Executed in context of uploader thread
+     *
+     * @param jobId
+     *            the id of the job
+     * @param status
+     *            the status of the job
+     */
+    public void setUploadStatus(String jobId, Status status) {
+        UploadJob uj = jobs.get(jobId);
+        if (uj == null) {
+            s_logger.warn("setUploadStatus for jobId: " + jobId + ", status=" + status + " no job found");
+            return;
+        }
+        TemplateUploader tu = uj.getTemplateUploader();
+        s_logger.warn("Upload Completion for jobId: " + jobId + ", status=" + status);
+        s_logger.warn("UploadedBytes=" + tu.getUploadedBytes() + ", error=" + tu.getUploadError() + ", pct=" + tu.getUploadPercent());
+
+        switch (status) {
+        case ABORTED:
+        case NOT_STARTED:
+        case UNRECOVERABLE_ERROR:
+            // Delete the entity only if its a volume. TO DO - find a better way of finding it a volume.
+            if (uj.getTemplateUploader().getUploadLocalPath().indexOf("volume") > -1) {
+                uj.cleanup();
+            }
+            break;
+        case UNKNOWN:
+            return;
+        case IN_PROGRESS:
+            s_logger.info("Resuming jobId: " + jobId + ", status=" + status);
+            tu.setResume(true);
+            threadPool.execute(tu);
+            break;
+        case RECOVERABLE_ERROR:
+            threadPool.execute(tu);
+            break;
+        case UPLOAD_FINISHED:
+            tu.setUploadError("Upload success, starting install ");
+            String result = postUpload(jobId);
+            if (result != null) {
+                s_logger.error("Failed post upload script: " + result);
+                tu.setStatus(Status.UNRECOVERABLE_ERROR);
+                tu.setUploadError("Failed post upload script: " + result);
+            } else {
+                s_logger.warn("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
+                tu.setStatus(Status.POST_UPLOAD_FINISHED);
+                tu.setUploadError("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
+            }
+            // Delete the entity only if its a volume. TO DO - find a better way of finding it a volume.
+            if (uj.getTemplateUploader().getUploadLocalPath().indexOf("volume") > -1) {
+                uj.cleanup();
+            }
+            break;
+        default:
+            break;
+        }
+    }
+
+    private String postUpload(String jobId) {
+        return null;
+    }
+
+    private void sleep() {
+        try {
+            Thread.sleep(3000);
+        } catch (InterruptedException e) {
+            // ignore
+        }
+    }
+
+    private boolean checkAndStartApache() {
+
+        //Check whether the Apache server is running
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("if [ -d /etc/apache2 ] ; then service apache2 status | grep pid; else service httpd status | grep pid; fi ");
+        String result = command.execute();
+
+        //Apache Server is not running. Try to start it.
+        if (result != null) {
+
+            /*s_logger.warn("Apache server not running, trying to start it");
+            String port = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
+            String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
+
+            command = new Script("/bin/bash", s_logger);
+            command.add("-c");
+            command.add("iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j DROP;" +
+                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j HTTP;" +
+                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j DROP;" +
+                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j HTTP;" +
+                        "iptables -F HTTP;" +
+                        "iptables -X HTTP;" +
+                        "iptables -N HTTP;" +
+                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j DROP;" +
+                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j DROP;" +
+                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j HTTP;" +
+                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j HTTP;");
+
+            result = command.execute();
+            if (result != null) {
+                s_logger.warn("Error in opening up httpd port err=" + result );
+                return false;
+            }*/
+
+            command = new Script("/bin/bash", s_logger);
+            command.add("-c");
+            command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
+            result = command.execute();
+            if (result != null) {
+                s_logger.warn("Error in starting httpd service err=" + result);
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
new file mode 100644
index 0000000..e0fcbae
--- /dev/null
+++ b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.storage.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+
+import javax.naming.ConfigurationException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import org.apache.cloudstack.storage.command.CopyCmdAnswer;
+import org.apache.cloudstack.storage.command.CopyCommand;
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
+
+import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.ListTemplateAnswer;
+import com.cloud.agent.api.storage.ListTemplateCommand;
+import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.agent.api.to.SwiftTO;
+import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.Storage;
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class LocalNfsSecondaryStorageResourceTest extends TestCase {
+    private static Map<String, Object> testParams;
+
+    private static final Logger s_logger = Logger.getLogger(LocalNfsSecondaryStorageResourceTest.class.getName());
+
+    LocalNfsSecondaryStorageResource resource;
+
+    @Before
+    @Override
+    public void setUp() throws ConfigurationException {
+        resource = new LocalNfsSecondaryStorageResource();
+        resource.setInSystemVM(true);
+
+        testParams = PropertiesUtil.toMap(loadProperties());
+        resource.configureStorageLayerClass(testParams);
+        Object testLocalRoot = testParams.get("testLocalRoot");
+        resource.setParentPath("/mnt");
+
+        if (testLocalRoot != null) {
+            resource.setParentPath((String)testLocalRoot);
+        }
+
+        System.setProperty("paths.script", "/Users/edison/develop/asf-master/script");
+        //resource.configure("test", new HashMap<String, Object>());
+    }
+
+    @Test
+    public void testExecuteRequest() throws Exception {
+        TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
+        NfsTO cacheStore = Mockito.mock(NfsTO.class);
+        Mockito.when(cacheStore.getUrl()).thenReturn("nfs://nfs2.lab.vmops.com/export/home/edison/");
+        SwiftTO swift = Mockito.mock(SwiftTO.class);
+        Mockito.when(swift.getEndPoint()).thenReturn("https://objects.dreamhost.com/auth");
+        Mockito.when(swift.getAccount()).thenReturn("cloudstack");
+        Mockito.when(swift.getUserName()).thenReturn("images");
+        Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u");
+
+        Mockito.when(template.getDataStore()).thenReturn(swift);
+        Mockito.when(template.getPath()).thenReturn("template/1/1/");
+        Mockito.when(template.isRequiresHvm()).thenReturn(true);
+        Mockito.when(template.getId()).thenReturn(1L);
+        Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD);
+        Mockito.when(template.getOrigUrl()).thenReturn("http://nfs1.lab.vmops.com/templates/test.bz2");
+        Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
+        Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
+
+        DownloadCommand cmd = new DownloadCommand(template, 100000L);
+        cmd.setCacheStore(cacheStore);
+        DownloadAnswer answer = (DownloadAnswer)resource.executeRequest(cmd);
+        Assert.assertTrue(answer.getResult());
+
+        Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
+        Mockito.when(template.getDataStore()).thenReturn(swift);
+        //download swift:
+        Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
+        TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
+        Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
+        Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore);
+        Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
+        CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true);
+        CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer)resource.executeRequest(cpyCmd);
+        Assert.assertTrue(copyCmdAnswer.getResult());
+
+        //list template
+        ListTemplateCommand listCmd = new ListTemplateCommand(swift);
+        ListTemplateAnswer listAnswer = (ListTemplateAnswer)resource.executeRequest(listCmd);
+
+        Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0);
+    }
+
+    public static Properties loadProperties() throws ConfigurationException {
+        Properties properties = new Properties();
+        final File file = PropertiesUtil.findConfigFile("agent.properties");
+        if (file == null) {
+            throw new ConfigurationException("Unable to find agent.properties.");
+        }
+
+        s_logger.info("agent.properties found at " + file.getAbsolutePath());
+
+        try {
+            properties.load(new FileInputStream(file));
+        } catch (final FileNotFoundException ex) {
+            throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
+        } catch (final IOException ex) {
+            throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
+        }
+        return properties;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java
new file mode 100644
index 0000000..e0ae4c5
--- /dev/null
+++ b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.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.storage.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.ConfigurationException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class NfsSecondaryStorageResourceTest extends TestCase {
+    private static Map<String, Object> testParams;
+
+    private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResourceTest.class.getName());
+
+    NfsSecondaryStorageResource resource;
+
+    @Before
+    @Override
+    public void setUp() throws ConfigurationException {
+        s_logger.setLevel(Level.ALL);
+        resource = new NfsSecondaryStorageResource();
+        resource.setInSystemVM(true);
+        testParams = PropertiesUtil.toMap(loadProperties());
+        resource.configureStorageLayerClass(testParams);
+        Object testLocalRoot = testParams.get("testLocalRoot");
+        if (testLocalRoot != null) {
+            resource.setParentPath((String)testLocalRoot);
+        }
+    }
+
+    @Test
+    public void testMount() throws Exception {
+        String sampleUriStr = "cifs://192.168.1.128/CSHV3?user=administrator&password=1pass%40word1&foo=bar";
+        URI sampleUri = new URI(sampleUriStr);
+
+        s_logger.info("Check HostIp parsing");
+        String hostIpStr = resource.getUriHostIp(sampleUri);
+        Assert.assertEquals("Expected host IP " + sampleUri.getHost() + " and actual host IP " + hostIpStr + " differ.", sampleUri.getHost(), hostIpStr);
+
+        s_logger.info("Check option parsing");
+        String expected = "user=administrator,password=1pass@word1,foo=bar,";
+        String actualOpts = resource.parseCifsMountOptions(sampleUri);
+        Assert.assertEquals("Options should be " + expected + " and not " + actualOpts, expected, actualOpts);
+
+        // attempt a configured mount
+        final Map<String, Object> params = PropertiesUtil.toMap(loadProperties());
+        String sampleMount = (String)params.get("testCifsMount");
+        if (!sampleMount.isEmpty()) {
+            s_logger.info("functional test, mount " + sampleMount);
+            URI realMntUri = new URI(sampleMount);
+            String mntSubDir = resource.mountUri(realMntUri);
+            s_logger.info("functional test, umount " + mntSubDir);
+            resource.umount(resource.getMountingRoot() + mntSubDir, realMntUri);
+        } else {
+            s_logger.info("no entry for testCifsMount in " + "./conf/agent.properties - skip functional test");
+        }
+    }
+
+    public static Properties loadProperties() throws ConfigurationException {
+        Properties properties = new Properties();
+        final File file = PropertiesUtil.findConfigFile("agent.properties");
+        if (file == null) {
+            throw new ConfigurationException("Unable to find agent.properties.");
+        }
+
+        s_logger.info("agent.properties found at " + file.getAbsolutePath());
+
+        try {
+            properties.load(new FileInputStream(file));
+        } catch (final FileNotFoundException ex) {
+            throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
+        } catch (final IOException ex) {
+            throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
+        }
+        return properties;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java
deleted file mode 100644
index 9393ee2..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.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 org.apache.cloudstack.storage.resource;
-
-import java.net.URI;
-import java.util.concurrent.Executors;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import org.apache.cloudstack.storage.template.DownloadManagerImpl;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-import com.cloud.storage.JavaStorageLayer;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
-
-@Component
-public class LocalNfsSecondaryStorageResource extends NfsSecondaryStorageResource {
-
-    private static final Logger s_logger = Logger.getLogger(LocalNfsSecondaryStorageResource.class);
-
-    public LocalNfsSecondaryStorageResource() {
-        this._dlMgr = new DownloadManagerImpl();
-        ((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
-        _storage = new JavaStorageLayer();
-        this._inSystemVM = false;
-    }
-
-    @Override
-    public void setParentPath(String path) {
-        this._parent = path;
-    }
-
-    @Override
-    public Answer executeRequest(Command cmd) {
-        return super.executeRequest(cmd);
-    }
-
-    @Override
-    synchronized public String getRootDir(String secUrl) {
-        try {
-            URI uri = new URI(secUrl);
-            String dir = mountUri(uri);
-            return _parent + "/" + dir;
-        } catch (Exception e) {
-            String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
-            s_logger.error(msg, e);
-            throw new CloudRuntimeException(msg);
-        }
-    }
-
-    @Override
-    protected void mount(String localRootPath, String remoteDevice, URI uri) {
-        ensureLocalRootPathExists(localRootPath, uri);
-
-        if (mountExists(localRootPath, uri)) {
-            return;
-        }
-
-        attemptMount(localRootPath, remoteDevice, uri);
-
-        // Change permissions for the mountpoint - seems to bypass authentication
-        Script script = new Script(true, "chmod", _timeout, s_logger);
-        script.add("777", localRootPath);
-        String result = script.execute();
-        if (result != null) {
-            String errMsg = "Unable to set permissions for " + localRootPath + " due to " + result;
-            s_logger.error(errMsg);
-            throw new CloudRuntimeException(errMsg);
-        }
-        s_logger.debug("Successfully set 777 permission for " + localRootPath);
-
-        // XXX: Adding the check for creation of snapshots dir here. Might have
-        // to move it somewhere more logical later.
-        checkForSnapshotsDir(localRootPath);
-        checkForVolumesDir(localRootPath);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
deleted file mode 100644
index bdfe7e8..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
+++ /dev/null
@@ -1,240 +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.storage.resource;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.storage.command.DownloadCommand;
-import org.apache.cloudstack.storage.command.DownloadProgressCommand;
-import org.apache.cloudstack.storage.template.DownloadManager;
-import org.apache.cloudstack.storage.template.DownloadManagerImpl;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.CheckHealthAnswer;
-import com.cloud.agent.api.CheckHealthCommand;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.ComputeChecksumCommand;
-import com.cloud.agent.api.PingCommand;
-import com.cloud.agent.api.PingStorageCommand;
-import com.cloud.agent.api.ReadyAnswer;
-import com.cloud.agent.api.ReadyCommand;
-import com.cloud.agent.api.SecStorageSetupCommand;
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupStorageCommand;
-import com.cloud.agent.api.storage.ListTemplateAnswer;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.to.NfsTO;
-import com.cloud.host.Host;
-import com.cloud.host.Host.Type;
-import com.cloud.resource.ServerResourceBase;
-import com.cloud.storage.Storage;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.storage.StorageLayer;
-import com.cloud.storage.template.TemplateProp;
-import com.cloud.utils.component.ComponentContext;
-
-public class LocalSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
-    private static final Logger s_logger = Logger.getLogger(LocalSecondaryStorageResource.class);
-    int _timeout;
-
-    String _instance;
-    String _parent;
-
-    String _dc;
-    String _pod;
-    String _guid;
-
-    StorageLayer _storage;
-
-    DownloadManager _dlMgr;
-
-    @Override
-    public void disconnected() {
-    }
-
-    @Override
-    public String getRootDir(String url) {
-        return getRootDir();
-
-    }
-
-    public String getRootDir() {
-        return _parent;
-    }
-
-    @Override
-    public Answer executeRequest(Command cmd) {
-        if (cmd instanceof DownloadProgressCommand) {
-            return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
-        } else if (cmd instanceof DownloadCommand) {
-            return _dlMgr.handleDownloadCommand(this, (DownloadCommand)cmd);
-        } else if (cmd instanceof CheckHealthCommand) {
-            return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
-        } else if (cmd instanceof SecStorageSetupCommand) {
-            return new Answer(cmd, true, "success");
-        } else if (cmd instanceof ReadyCommand) {
-            return new ReadyAnswer((ReadyCommand)cmd);
-        } else if (cmd instanceof ListTemplateCommand) {
-            return execute((ListTemplateCommand)cmd);
-        } else if (cmd instanceof ComputeChecksumCommand) {
-            return execute((ComputeChecksumCommand)cmd);
-        } else {
-            return Answer.createUnsupportedCommandAnswer(cmd);
-        }
-    }
-
-    private Answer execute(ComputeChecksumCommand cmd) {
-        return new Answer(cmd, false, null);
-    }
-
-    private Answer execute(ListTemplateCommand cmd) {
-        String root = getRootDir();
-        Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
-        return new ListTemplateAnswer(((NfsTO)cmd.getDataStore()).getUrl(), templateInfos);
-    }
-
-    @Override
-    public Type getType() {
-        return Host.Type.LocalSecondaryStorage;
-    }
-
-    @Override
-    public PingCommand getCurrentStatus(final long id) {
-        return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        _guid = (String)params.get("guid");
-        if (_guid == null) {
-            throw new ConfigurationException("Unable to find the guid");
-        }
-
-        _dc = (String)params.get("zone");
-        if (_dc == null) {
-            throw new ConfigurationException("Unable to find the zone");
-        }
-        _pod = (String)params.get("pod");
-
-        _instance = (String)params.get("instance");
-
-        _parent = (String)params.get("mount.path");
-        if (_parent == null) {
-            throw new ConfigurationException("No directory specified.");
-        }
-
-        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
-        if (_storage == null) {
-            String value = (String)params.get(StorageLayer.ClassConfigKey);
-            if (value == null) {
-                value = "com.cloud.storage.JavaStorageLayer";
-            }
-
-            try {
-                Class<StorageLayer> clazz = (Class<StorageLayer>)Class.forName(value);
-                _storage = ComponentContext.inject(clazz);
-            } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Unable to find class " + value);
-            }
-        }
-
-        if (!_storage.mkdirs(_parent)) {
-            s_logger.warn("Unable to create the directory " + _parent);
-            throw new ConfigurationException("Unable to create the directory " + _parent);
-        }
-
-        s_logger.info("Mount point established at " + _parent);
-
-        params.put("template.parent", _parent);
-        params.put(StorageLayer.InstanceConfigKey, _storage);
-
-        _dlMgr = new DownloadManagerImpl();
-        _dlMgr.configure("DownloadManager", params);
-
-        return true;
-    }
-
-    @Override
-    public boolean start() {
-        return true;
-    }
-
-    @Override
-    public boolean stop() {
-        return true;
-    }
-
-    @Override
-    public StartupCommand[] initialize() {
-
-        final StartupStorageCommand cmd =
-            new StartupStorageCommand(_parent, StoragePoolType.Filesystem, 1024l * 1024l * 1024l * 1024l, _dlMgr.gatherTemplateInfo(_parent));
-        cmd.setResourceType(Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE);
-        cmd.setIqn("local://");
-        fillNetworkInformation(cmd);
-        cmd.setDataCenter(_dc);
-        cmd.setPod(_pod);
-        cmd.setGuid(_guid);
-        cmd.setName(_guid);
-        cmd.setVersion(LocalSecondaryStorageResource.class.getPackage().getImplementationVersion());
-
-        return new StartupCommand[] {cmd};
-    }
-
-    @Override
-    protected String getDefaultScriptsDir() {
-        return "scripts/storage/secondary";
-    }
-
-    @Override
-    public void setName(String name) {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public void setConfigParams(Map<String, Object> params) {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public Map<String, Object> getConfigParams() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public int getRunLevel() {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public void setRunLevel(int level) {
-        // TODO Auto-generated method stub
-
-    }
-}


[38/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fix two NPE exceptions in the Contrail Plugin when contrail is not providing any services on the network.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/64c61c72
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/64c61c72
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/64c61c72

Branch: refs/heads/rbac
Commit: 64c61c720234676300f0295285342bbd45686fa6
Parents: cbbe3e0
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Thu Feb 6 16:49:52 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Thu Feb 6 16:51:20 2014 +0100

----------------------------------------------------------------------
 .../contrail/management/ContrailGuru.java       | 42 ++++++++++++--------
 1 file changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/64c61c72/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
index 0bb95dd..f81c0d0 100644
--- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
@@ -21,8 +21,8 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.List;
 
-import javax.inject.Inject;
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import net.juniper.contrail.api.types.MacAddressesType;
 import net.juniper.contrail.api.types.VirtualMachineInterface;
@@ -34,14 +34,15 @@ import org.apache.cloudstack.network.contrail.model.VMInterfaceModel;
 import org.apache.cloudstack.network.contrail.model.VirtualMachineModel;
 import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel;
 
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkProfile;
@@ -49,25 +50,24 @@ import com.cloud.network.Networks.AddressFormat;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.Mode;
 import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.addr.PublicIp;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.guru.NetworkGuru;
-import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
-import com.cloud.network.dao.IPAddressVO;
-import com.cloud.network.addr.PublicIp;
+import com.cloud.network.guru.NetworkGuru;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
-import com.cloud.network.dao.IPAddressDao;
-import com.cloud.user.AccountManager;
-import com.cloud.network.IpAddressManager;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachineProfile;
@@ -96,6 +96,16 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
     private static final TrafficType[] TrafficTypes = {TrafficType.Guest};
 
     private boolean canHandle(NetworkOffering offering, NetworkType networkType, PhysicalNetwork physicalNetwork) {
+        if (physicalNetwork == null) {
+            // Physical network can be false for system network during initial setup of CloudStack
+            return false;
+        }
+
+        if (_manager.getRouterOffering() == null || _manager.getVpcRouterOffering() == null) {
+            // FIXME The resource is apparently not configured, we need another way to check this.
+            return false;
+        }
+
         if (networkType == NetworkType.Advanced
                 && (offering.getId() == _manager.getRouterOffering().getId() || offering.getId() == _manager.getVpcRouterOffering().getId())
                 && isMyTrafficType(offering.getTrafficType())
@@ -121,8 +131,8 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
             return null;
         }
         NetworkVO network =
-            new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch, offering.getId(), State.Allocated, plan.getDataCenterId(),
-                plan.getPhysicalNetworkId());
+                new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch, offering.getId(), State.Allocated, plan.getDataCenterId(),
+                        plan.getPhysicalNetworkId());
         if (userSpecified.getCidr() != null) {
             network.setCidr(userSpecified.getCidr());
             network.setGateway(userSpecified.getGateway());
@@ -133,7 +143,7 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
 
     @Override
     public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context)
-        throws InsufficientVirtualNetworkCapcityException {
+            throws InsufficientVirtualNetworkCapcityException {
         s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
 
         VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
@@ -180,7 +190,7 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
      */
     @Override
     public NicProfile allocate(Network network, NicProfile profile, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
-        InsufficientAddressCapacityException, ConcurrentOperationException {
+    InsufficientAddressCapacityException, ConcurrentOperationException {
         s_logger.debug("allocate NicProfile on " + network.getName());
 
         if (profile != null && profile.getRequestedIpv4() != null) {
@@ -207,7 +217,7 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
      */
     @Override
     public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
-        throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
+            throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
         s_logger.debug("reserve NicProfile on network id: " + network.getId() + " " + network.getName());
         s_logger.debug("deviceId: " + nic.getDeviceId());
 


[33/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6001: Fixed hyperv vm console not working for 3 minutes after migration.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/13e0f293
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/13e0f293
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/13e0f293

Branch: refs/heads/rbac
Commit: 13e0f293edc718a9ee03c56896b65240cdc86d34
Parents: 86cada3
Author: Anshul Gangwar <an...@citrix.com>
Authored: Fri Jan 31 13:04:36 2014 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Thu Feb 6 13:47:38 2014 +0530

----------------------------------------------------------------------
 .../consoleproxy/ConsoleProxyRdpClient.java     | 147 ++++++++++---------
 1 file changed, 78 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13e0f293/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java
index d5a3fcd..7d49b19 100644
--- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java
+++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java
@@ -19,7 +19,6 @@ package com.cloud.consoleproxy;
 import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 import org.apache.log4j.Logger;
@@ -55,7 +54,8 @@ public class ConsoleProxyRdpClient extends ConsoleProxyClientBase {
     private RdpBufferedImageCanvas _canvas = null;
 
     private Thread _worker;
-    private volatile boolean _workerDone = false;
+    private volatile boolean _workerDone = true;
+    private volatile long _threadStopTime;
 
     private AwtMouseEventSource _mouseEventSource = null;
     private AwtKeyEventSource _keyEventSource = null;
@@ -231,77 +231,86 @@ public class ConsoleProxyRdpClient extends ConsoleProxyClientBase {
 
     @Override
     public void initClient(final ConsoleProxyClientParam param) {
-        _workerDone = false;
-
-        int canvasWidth = 1024;
-        int canvasHeight = 768;
-        setClientParam(param);
-
-        final String host = param.getHypervHost();
-        final String password = param.getPassword();
-        final String instanceId = param.getClientHostAddress();
-        final int port = param.getClientHostPort();
-
-        _screen = new ScreenDescription();
-        _canvas = new RdpBufferedImageCanvas(this, canvasWidth, canvasHeight);
-        onFramebufferSizeChange(canvasWidth, canvasHeight);
-
-        _screen.addSizeChangeListener(new SizeChangeListener() {
-            @Override
-            public void sizeChanged(int width, int height) {
-                if (_canvas != null) {
-                    _canvas.setCanvasSize(width, height);
-                }
-            }
-        });
+        if ((System.currentTimeMillis() - _threadStopTime) < 1000) {
+            return;
+        }
 
-        final SSLState sslState = new SSLState();
+        try {
+            int canvasWidth = 1024;
+            int canvasHeight = 768;
+            setClientParam(param);
+
+            final String host = param.getHypervHost();
+            final String password = param.getPassword();
+            final String instanceId = param.getClientHostAddress();
+            final int port = param.getClientHostPort();
+
+            final SSLState sslState = new SSLState();
+
+            final String username = param.getUsername();
+            String name = null;
+            String domain = null;
+            if (username.contains("\\")) {
+                String[] tokens = username.split("\\\\");
+                name = tokens[1];
+                domain = tokens[0];
+            } else {
+                name = username;
+                domain = "Workgroup";
+            }
 
-        final String username = param.getUsername();
-        String name = null;
-        String domain = null;
-        if (username.contains("\\")) {
-            String[] tokens = username.split("\\\\");
-            name = tokens[1];
-            domain = tokens[0];
-        } else {
-            name = username;
-            domain = "Workgroup";
-        }
+            _screen = new ScreenDescription();
+            _canvas = new RdpBufferedImageCanvas(this, canvasWidth, canvasHeight);
+            onFramebufferSizeChange(canvasWidth, canvasHeight);
 
-        _client = new RdpClient("client", host, domain, name, password, instanceId, _screen, _canvas,
-                sslState);
-
-        _mouseEventSource = _client.getMouseEventSource();
-        _keyEventSource = _client.getKeyEventSource();
-
-        _worker = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                _socket = new AprSocketWrapperImpl("socket", sslState);
-                Pipeline pipeline = new PipelineImpl("Client");
-                pipeline.add(_socket, _client);
-                pipeline.link("socket", _client.getId(), "socket");
-                pipeline.validate();
-
-                InetSocketAddress address = new InetSocketAddress(host, port);
-                ConsoleProxy.ensureRoute(host);
-
-                try {
-                    // Connect socket to remote server and run main loop(s)
-                    _socket.connect(address);
-                } catch (IOException e) {
-                    e.printStackTrace();
-                } finally {
-                    shutdown();
+            _screen.addSizeChangeListener(new SizeChangeListener() {
+                @Override
+                public void sizeChanged(int width, int height) {
+                    if (_canvas != null) {
+                        _canvas.setCanvasSize(width, height);
+                    }
                 }
-
-                s_logger.info("Receiver thread stopped.");
-                _workerDone = true;
-            }
-        });
-        _worker.setDaemon(true);
-        _worker.start();
+            });
+
+            s_logger.info("connecting to instance " + instanceId + " on host " + host);
+            _client = new RdpClient("client", host, domain, name, password, instanceId, _screen, _canvas, sslState);
+
+            _mouseEventSource = _client.getMouseEventSource();
+            _keyEventSource = _client.getKeyEventSource();
+
+            _worker = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    _socket = new AprSocketWrapperImpl("socket", sslState);
+                    Pipeline pipeline = new PipelineImpl("Client");
+                    pipeline.add(_socket, _client);
+                    pipeline.link("socket", _client.getId(), "socket");
+                    pipeline.validate();
+
+                    InetSocketAddress address = new InetSocketAddress(host, port);
+                    ConsoleProxy.ensureRoute(host);
+
+                    try {
+                        _workerDone = false;
+                        s_logger.info("Connecting socket to remote server and run main loop(s)");
+                        _socket.connect(address);
+                    } catch (Exception e) {
+                        s_logger.info(" error occurred in connecting to socket " + e.getMessage());
+                    } finally {
+                        shutdown();
+                    }
+
+                    _threadStopTime = System.currentTimeMillis();
+                    s_logger.info("Receiver thread stopped.");
+                    _workerDone = true;
+                }
+            });
+            _worker.setDaemon(true);
+            _worker.start();
+        } catch (Exception e) {
+            _workerDone = true;
+            s_logger.info("error occurred in initializing rdp client " + e.getMessage());
+        }
     }
 
     @Override


[39/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6044: Primary storage list: truncate long values


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/91672863
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/91672863
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/91672863

Branch: refs/heads/rbac
Commit: 916728634b5d4af359269a41d655466fd628554b
Parents: 64c61c7
Author: Brian Federle <br...@citrix.com>
Authored: Thu Feb 6 09:50:09 2014 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Thu Feb 6 09:50:41 2014 -0800

----------------------------------------------------------------------
 ui/scripts/system.js | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91672863/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index 11dd0ba..ba5746e 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -14885,16 +14885,19 @@
                     section: 'primary-storage',
                     fields: {
                         name: {
-                            label: 'label.name'
+                            label: 'label.name',
+                            truncate: true
                         },
                         ipaddress: {
                             label: 'label.server'
                         },
                         path: {
-                            label: 'label.path'
+                            label: 'label.path',
+                            truncate: true
                         },
                         clustername: {
-                            label: 'label.cluster'
+                            label: 'label.cluster',
+                            truncate: true
                         },
                         scope: {
                             label: 'Scope'


[17/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Sync systemvm and systemvm64 build instructions


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3df97bd6
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3df97bd6
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3df97bd6

Branch: refs/heads/rbac
Commit: 3df97bd663c6a7e605816996b8bf02d3dec3730f
Parents: a24263f
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 11:19:41 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 11:21:23 2014 +0100

----------------------------------------------------------------------
 .../appliance/definitions/systemvm64template/base.sh  |  6 +++---
 .../definitions/systemvm64template/postinstall.sh     | 14 +++++++-------
 tools/appliance/definitions/systemvmtemplate/base.sh  |  4 +---
 .../definitions/systemvmtemplate/postinstall.sh       | 10 ++++++++--
 4 files changed, 19 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3df97bd6/tools/appliance/definitions/systemvm64template/base.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvm64template/base.sh b/tools/appliance/definitions/systemvm64template/base.sh
index 46c5db6..bc03ffe 100644
--- a/tools/appliance/definitions/systemvm64template/base.sh
+++ b/tools/appliance/definitions/systemvm64template/base.sh
@@ -1,11 +1,11 @@
 # Update the box
 apt-get -y update
-#apt-get -y install linux-headers-$(uname -r) build-essential
-#apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
 apt-get -y install curl unzip
+apt-get clean
 
-# Set up sudo
+# Set up sudo, TODO: Check security concerns
 echo 'vagrant ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/vagrant
+echo 'cloud ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/cloud
 
 # Tweak sshd to prevent DNS resolution (speed up logins)
 echo 'UseDNS no' >> /etc/ssh/sshd_config

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3df97bd6/tools/appliance/definitions/systemvm64template/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvm64template/postinstall.sh b/tools/appliance/definitions/systemvm64template/postinstall.sh
index 1eddbdb..a9e0b89 100644
--- a/tools/appliance/definitions/systemvm64template/postinstall.sh
+++ b/tools/appliance/definitions/systemvm64template/postinstall.sh
@@ -19,7 +19,7 @@ set -x
 
 ROOTPW=password
 HOSTNAME=systemvm
-CLOUDSTACK_RELEASE=4.3.0
+CLOUDSTACK_RELEASE=4.4.0
 
 add_backports () {
     sed -i '/backports/d' /etc/apt/sources.list
@@ -27,7 +27,6 @@ add_backports () {
     apt-get update
 }
 
-
 install_packages() {
   DEBIAN_FRONTEND=noninteractive
   DEBIAN_PRIORITY=critical
@@ -51,8 +50,8 @@ install_packages() {
   apt-get --no-install-recommends -q -y --force-yes install nfs-common
   # nfs irqbalance
   apt-get --no-install-recommends -q -y --force-yes install irqbalance
-  
- # cifs client
+
+  # cifs client
   apt-get --no-install-recommends -q -y --force-yes install samba-common
   apt-get --no-install-recommends -q -y --force-yes install cifs-utils
 
@@ -76,12 +75,13 @@ install_packages() {
   echo "iptables-persistent iptables-persistent/autosave_v6 boolean true" | debconf-set-selections
   apt-get --no-install-recommends -q -y --force-yes install iptables-persistent
   
-  # Hyperv  kvp daemon
+  # Hyperv  kvp daemon - 64bit only
   # Download the hv kvp daemon 
   wget http://people.apache.org/~rajeshbattala/hv-kvp-daemon_3.1_amd64.deb
   dpkg -i hv-kvp-daemon_3.1_amd64.deb
+
   #libraries required for rdp client (Hyper-V) 
-   apt-get --no-install-recommends -q -y --force-yes install libtcnative-1 libssl-dev libapr1-dev
+  apt-get --no-install-recommends -q -y --force-yes install libtcnative-1 libssl-dev libapr1-dev
 
   # vmware tools
   apt-get --no-install-recommends -q -y --force-yes install open-vm-tools
@@ -221,7 +221,7 @@ configure_services() {
   snapshot_dir="/opt/cloudstack*"
   cd /opt
   wget --no-check-certificate $snapshot_url -O cloudstack.tar.gz
-  tar -zxvf cloudstack.tar.gz
+  tar -zxvf cloudstack.tar.gz 'cloudstack-HEAD-???????/systemvm'
   cp -rv $snapshot_dir/systemvm/patches/debian/config/* /
   cp -rv $snapshot_dir/systemvm/patches/debian/vpn/* /
   mkdir -p /usr/share/cloud/

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3df97bd6/tools/appliance/definitions/systemvmtemplate/base.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/base.sh b/tools/appliance/definitions/systemvmtemplate/base.sh
index 5aaa0ed..bc03ffe 100644
--- a/tools/appliance/definitions/systemvmtemplate/base.sh
+++ b/tools/appliance/definitions/systemvmtemplate/base.sh
@@ -1,12 +1,10 @@
 # Update the box
 apt-get -y update
-#below are needed for ruby perhaps
-#apt-get -y install linux-headers-$(uname -r) build-essential
-#apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
 apt-get -y install curl unzip
 apt-get clean
 
 # Set up sudo, TODO: Check security concerns
+echo 'vagrant ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/vagrant
 echo 'cloud ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/cloud
 
 # Tweak sshd to prevent DNS resolution (speed up logins)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3df97bd6/tools/appliance/definitions/systemvmtemplate/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/postinstall.sh b/tools/appliance/definitions/systemvmtemplate/postinstall.sh
index 175fc1f..d613483 100644
--- a/tools/appliance/definitions/systemvmtemplate/postinstall.sh
+++ b/tools/appliance/definitions/systemvmtemplate/postinstall.sh
@@ -19,7 +19,7 @@ set -x
 
 ROOTPW=password
 HOSTNAME=systemvm
-CLOUDSTACK_RELEASE=4.2.0
+CLOUDSTACK_RELEASE=4.4.0
 
 add_backports () {
     sed -i '/backports/d' /etc/apt/sources.list
@@ -51,6 +51,9 @@ install_packages() {
   # nfs irqbalance
   apt-get --no-install-recommends -q -y --force-yes install irqbalance
 
+  # cifs client
+  apt-get --no-install-recommends -q -y --force-yes install samba-common
+  apt-get --no-install-recommends -q -y --force-yes install cifs-utils
 
   # vpn stuff
   apt-get --no-install-recommends -q -y --force-yes install xl2tpd bcrelay ppp ipsec-tools tdb-tools
@@ -72,6 +75,9 @@ install_packages() {
   echo "iptables-persistent iptables-persistent/autosave_v6 boolean true" | debconf-set-selections
   apt-get --no-install-recommends -q -y --force-yes install iptables-persistent
 
+  #libraries required for rdp client (Hyper-V) 
+  apt-get --no-install-recommends -q -y --force-yes install libtcnative-1 libssl-dev libapr1-dev
+
   # vmware tools
   apt-get --no-install-recommends -q -y --force-yes install open-vm-tools
   # commented installaion of vmware-tools  as we are using the opensource open-vm-tools:
@@ -205,7 +211,7 @@ configure_services() {
   snapshot_dir="/opt/cloudstack*"
   cd /opt
   wget --no-check-certificate $snapshot_url -O cloudstack.tar.gz
-  tar -zxvf cloudstack.tar.gz
+  tar -zxvf cloudstack.tar.gz 'cloudstack-HEAD-???????/systemvm'
   cp -rv $snapshot_dir/systemvm/patches/debian/config/* /
   cp -rv $snapshot_dir/systemvm/patches/debian/vpn/* /
   mkdir -p /usr/share/cloud/


[27/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fixed the build broken by changes made to MonitoringServiceVO


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a873a0ef
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a873a0ef
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a873a0ef

Branch: refs/heads/rbac
Commit: a873a0efdd54ed131653837529ef4039ff961873
Parents: 9641e1d
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Feb 5 10:35:49 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Feb 5 10:37:03 2014 -0800

----------------------------------------------------------------------
 .../cloud/network/router/VirtualNetworkApplianceManagerImpl.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a873a0ef/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 413b410..1673cac 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -42,8 +42,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd;
@@ -58,6 +56,7 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
+import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;


[29/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6031: UI > infrastructure > count > pass listAll=true to all listXXXXXXX API for counting resource.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/75757e94
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/75757e94
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/75757e94

Branch: refs/heads/rbac
Commit: 75757e94254dcacf746dea70b4784b8d4afe45c2
Parents: c2c7d33
Author: Jessica Wang <je...@apache.org>
Authored: Wed Feb 5 14:09:27 2014 -0800
Committer: Jessica Wang <je...@apache.org>
Committed: Wed Feb 5 14:38:16 2014 -0800

----------------------------------------------------------------------
 ui/scripts/system.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75757e94/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index 955d391..11dd0ba 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -210,6 +210,11 @@
                     zoneCount: function (data) {
                         $.ajax({
                             url: createURL('listZones'),
+                            data: {
+                            	listAll: true,
+                                page: 1,
+                                pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
+                            },
                             success: function (json) {
                                 dataFns.podCount($.extend(data, {
                                     zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0,
@@ -223,6 +228,7 @@
                         $.ajax({
                             url: createURL('listPods'),
                             data: {
+                            	listAll: true,
                                 page: 1,
                                 pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                             },
@@ -238,6 +244,7 @@
                         $.ajax({
                             url: createURL('listClusters'),
                             data: {
+                            	listAll: true,
                                 page: 1,
                                 pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                             },
@@ -261,6 +268,7 @@
                     hostCount: function (data) {
                         var data2 = {
                             type: 'routing',
+                            listAll: true,
                             page: 1,
                             pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                         };
@@ -277,6 +285,7 @@
                     
                     primaryStorageCount: function (data) {
                         var data2 = {
+                        	listAll: true,
                             page: 1,
                             pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                         };
@@ -294,6 +303,7 @@
                     secondaryStorageCount: function (data) {
                         var data2 = {
                             type: 'SecondaryStorage',
+                            listAll: true,
                             page: 1,
                             pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                         };
@@ -312,6 +322,7 @@
                         $.ajax({
                             url: createURL('listSystemVms'),
                             data: {
+                            	listAll: true,
                                 page: 1,
                                 pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                             },
@@ -325,6 +336,7 @@
                     
                     virtualRouterCount: function (data) {
                         var data2 = {
+                        	listAll: true,
                             page: 1,
                             pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
                         };


[43/50] [abbrv] Revert "CLOUDSTACK-6003 fixing plus refactoring dispatcher" as it breaks API dispatching for commands having Map as a parameter type

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 290e9de..d715db6 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -43,6 +43,8 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
@@ -84,7 +86,6 @@ import org.springframework.stereotype.Component;
 
 import org.apache.cloudstack.acl.APIChecker;
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.BaseAsyncCreateCmd;
@@ -121,7 +122,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 
-import com.cloud.api.dispatch.DispatchChainFactory;
 import com.cloud.api.response.ApiResponseSerializer;
 import com.cloud.configuration.Config;
 import com.cloud.domain.Domain;
@@ -159,14 +159,12 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
     private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
 
-    public static boolean encodeApiResponse = false;
-    public static String jsonContentType = "text/javascript";
+    private static boolean encodeApiResponse = false;
+    private static String jsonContentType = "text/javascript";
+    private static String controlCharacters = "[\000-\011\013-\014\016-\037\177]"; // Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
+    @Inject ApiDispatcher _dispatcher;
 
     @Inject
-    protected ApiDispatcher _dispatcher;
-    @Inject()
-    protected DispatchChainFactory dispatchChainFactory = null;
-    @Inject
     private AccountManager _accountMgr;
     @Inject
     private DomainManager _domainMgr;
@@ -193,27 +191,27 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Override
-    public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
         return true;
     }
 
     @Override
     public boolean start() {
         Integer apiPort = null; // api port, null by default
-        final SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
+        SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
         sc.addAnd("name", SearchCriteria.Op.EQ, Config.IntegrationAPIPort.key());
-        final List<ConfigurationVO> values = _configDao.search(sc, null);
+        List<ConfigurationVO> values = _configDao.search(sc, null);
         if ((values != null) && (values.size() > 0)) {
-            final ConfigurationVO apiPortConfig = values.get(0);
+            ConfigurationVO apiPortConfig = values.get(0);
             if (apiPortConfig.getValue() != null) {
                 apiPort = Integer.parseInt(apiPortConfig.getValue());
             }
         }
 
-        final Map<String, String> configs = _configDao.getConfiguration();
-        final String strSnapshotLimit = configs.get(Config.ConcurrentSnapshotsThresholdPerHost.key());
+        Map<String, String> configs = _configDao.getConfiguration();
+        String strSnapshotLimit = configs.get(Config.ConcurrentSnapshotsThresholdPerHost.key());
         if (strSnapshotLimit != null) {
-            final Long snapshotLimit = NumbersUtil.parseLong(strSnapshotLimit, 1L);
+            Long snapshotLimit = NumbersUtil.parseLong(strSnapshotLimit, 1L);
             if (snapshotLimit.longValue() <= 0) {
                 s_logger.debug("Global config parameter " + Config.ConcurrentSnapshotsThresholdPerHost.toString() + " is less or equal 0; defaulting to unlimited");
             } else {
@@ -221,20 +219,20 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             }
         }
 
-        final Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
-        for (final PluggableService pluggableService : _pluggableServices) {
+        Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
+        for (PluggableService pluggableService : _pluggableServices) {
             cmdClasses.addAll(pluggableService.getCommands());
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Discovered plugin " + pluggableService.getClass().getSimpleName());
             }
         }
 
-        for (final Class<?> cmdClass : cmdClasses) {
-            final APICommand at = cmdClass.getAnnotation(APICommand.class);
+        for (Class<?> cmdClass : cmdClasses) {
+            APICommand at = cmdClass.getAnnotation(APICommand.class);
             if (at == null) {
                 throw new CloudRuntimeException(String.format("%s is claimed as a API command, but it doesn't have @APICommand annotation", cmdClass.getName()));
             }
-            final String apiName = at.name();
+            String apiName = at.name();
             if (s_apiNameCmdClassMap.containsKey(apiName)) {
                 s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
                 continue;
@@ -243,13 +241,13 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         }
 
         setEncodeApiResponse(Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key())));
-        final String jsonType = _configDao.getValue(Config.JavaScriptDefaultContentType.key());
+        String jsonType = _configDao.getValue(Config.JavaScriptDefaultContentType.key());
         if (jsonType != null) {
             jsonContentType = jsonType;
         }
 
         if (apiPort != null) {
-            final ListenerThread listenerThread = new ListenerThread(this, apiPort);
+            ListenerThread listenerThread = new ListenerThread(this, apiPort);
             listenerThread.start();
         }
 
@@ -260,13 +258,13 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     // If integration api port is not configured, actual OTW requests will be received by ApiServlet
     @SuppressWarnings({"unchecked", "rawtypes"})
     @Override
-    public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
+    public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
 
         // Create StringBuffer to log information in access log
-        final StringBuffer sb = new StringBuffer();
-        final HttpServerConnection connObj = (HttpServerConnection)context.getAttribute("http.connection");
+        StringBuffer sb = new StringBuffer();
+        HttpServerConnection connObj = (HttpServerConnection)context.getAttribute("http.connection");
         if (connObj instanceof SocketHttpServerConnection) {
-            final InetAddress remoteAddr = ((SocketHttpServerConnection)connObj).getRemoteAddress();
+            InetAddress remoteAddr = ((SocketHttpServerConnection)connObj).getRemoteAddress();
             sb.append(remoteAddr.toString() + " -- ");
         }
         sb.append(StringUtils.cleanString(request.getRequestLine().toString()));
@@ -275,7 +273,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             List<NameValuePair> paramList = null;
             try {
                 paramList = URLEncodedUtils.parse(new URI(request.getRequestLine().getUri()), "UTF-8");
-            } catch (final URISyntaxException e) {
+            } catch (URISyntaxException e) {
                 s_logger.error("Error parsing url request", e);
             }
 
@@ -284,9 +282,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             // APITODO: Use Guava's (import com.google.common.collect.Multimap;)
             // (Immutable)Multimap<String, String> paramMultiMap = HashMultimap.create();
             // Map<String, Collection<String>> parameterMap = paramMultiMap.asMap();
-            final Map parameterMap = new HashMap<String, String[]>();
+            Map parameterMap = new HashMap<String, String[]>();
             String responseType = BaseCmd.RESPONSE_TYPE_XML;
-            for (final NameValuePair param : paramList) {
+            for (NameValuePair param : paramList) {
                 if (param.getName().equalsIgnoreCase("response")) {
                     responseType = param.getValue();
                     continue;
@@ -306,15 +304,15 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 // always trust commands from API port, user context will always be UID_SYSTEM/ACCOUNT_ID_SYSTEM
                 CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
                 sb.insert(0, "(userId=" + User.UID_SYSTEM + " accountId=" + Account.ACCOUNT_ID_SYSTEM + " sessionId=" + null + ") ");
-                final String responseText = handleRequest(parameterMap, responseType, sb);
+                String responseText = handleRequest(parameterMap, responseType, sb);
                 sb.append(" 200 " + ((responseText == null) ? 0 : responseText.length()));
 
                 writeResponse(response, responseText, HttpStatus.SC_OK, responseType, null);
-            } catch (final ServerApiException se) {
-                final String responseText = getSerializedApiError(se, parameterMap, responseType);
+            } catch (ServerApiException se) {
+                String responseText = getSerializedApiError(se, parameterMap, responseType);
                 writeResponse(response, responseText, se.getErrorCode().getHttpCode(), responseType, se.getDescription());
                 sb.append(" " + se.getErrorCode() + " " + se.getDescription());
-            } catch (final RuntimeException e) {
+            } catch (RuntimeException e) {
                 // log runtime exception like NullPointerException to help identify the source easier
                 s_logger.error("Unhandled exception, ", e);
                 throw e;
@@ -327,70 +325,77 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
     @Override
     @SuppressWarnings("rawtypes")
-    public String handleRequest(final Map rawParams, final String responseType, final StringBuffer auditTrailSb) throws ServerApiException {
-        final Map<String, Object> params = ParameterHandler.unpackParams(rawParams);
-
+    public String handleRequest(Map params, String responseType, StringBuffer auditTrailSb) throws ServerApiException {
         String response = null;
-        String command = null;
+        String[] command = null;
 
         try {
-            command = (String) params.get(ApiConstants.COMMAND);
+            command = (String[])params.get("command");
             if (command == null) {
                 s_logger.error("invalid request, no command sent");
                 if (s_logger.isTraceEnabled()) {
                     s_logger.trace("dumping request parameters");
-                    for (final Object key : params.keySet()) {
-                        final String keyStr = (String)key;
-                        final Object value = params.get(key);
-                        s_logger.trace("   key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value));
+                    for (Object key : params.keySet()) {
+                        String keyStr = (String)key;
+                        String[] value = (String[])params.get(key);
+                        s_logger.trace("   key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value[0]));
                     }
                 }
                 throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent");
             } else {
-                final Map<String, String> paramMap = new HashMap<String, String>();
-                final Set keys = rawParams.keySet();
-                final Iterator keysIter = keys.iterator();
+                Map<String, String> paramMap = new HashMap<String, String>();
+                Set keys = params.keySet();
+                Iterator keysIter = keys.iterator();
                 while (keysIter.hasNext()) {
-                    final String key = (String)keysIter.next();
+                    String key = (String)keysIter.next();
                     if ("command".equalsIgnoreCase(key)) {
                         continue;
                     }
-                    final String[] value = (String[])rawParams.get(key);
+                    String[] value = (String[])params.get(key);
+                    // fail if parameter value contains ASCII control (non-printable) characters
+                    if (value[0] != null) {
+                        Pattern pattern = Pattern.compile(controlCharacters);
+                        Matcher matcher = pattern.matcher(value[0]);
+                        if (matcher.find()) {
+                            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Received value " + value[0] + " for parameter " + key +
+                                " is invalid, contains illegal ASCII non-printable characters");
+                        }
+                    }
                     paramMap.put(key, value[0]);
                 }
 
-                final Class<?> cmdClass = getCmdClass(command);
+                Class<?> cmdClass = getCmdClass(command[0]);
                 if (cmdClass != null) {
                     BaseCmd cmdObj = (BaseCmd)cmdClass.newInstance();
                     cmdObj = ComponentContext.inject(cmdObj);
                     cmdObj.configure();
                     cmdObj.setFullUrlParams(paramMap);
                     cmdObj.setResponseType(responseType);
-                    cmdObj.setHttpMethod(params.get(ApiConstants.HTTPMETHOD).toString());
+                    cmdObj.setHttpMethod(paramMap.get("httpmethod").toString());
 
                     // This is where the command is either serialized, or directly dispatched
-                    response = queueCommand(cmdObj, params);
-                    buildAuditTrail(auditTrailSb, command, response);
+                    response = queueCommand(cmdObj, paramMap);
+                    buildAuditTrail(auditTrailSb, command[0], response);
                 } else {
-                    if (!command.equalsIgnoreCase("login") && !command.equalsIgnoreCase("logout")) {
-                        final String errorString = "Unknown API command: " + command;
+                    if (!command[0].equalsIgnoreCase("login") && !command[0].equalsIgnoreCase("logout")) {
+                        String errorString = "Unknown API command: " + command[0];
                         s_logger.warn(errorString);
                         auditTrailSb.append(" " + errorString);
                         throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
                     }
                 }
             }
-        } catch (final InvalidParameterValueException ex) {
+        } catch (InvalidParameterValueException ex) {
             s_logger.info(ex.getMessage());
             throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
-        } catch (final IllegalArgumentException ex) {
+        } catch (IllegalArgumentException ex) {
             s_logger.info(ex.getMessage());
             throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
-        } catch (final PermissionDeniedException ex) {
-            final ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
+        } catch (PermissionDeniedException ex) {
+            ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
             if (idList != null) {
-                final StringBuffer buf = new StringBuffer();
-                for (final ExceptionProxyObject obj : idList) {
+                StringBuffer buf = new StringBuffer();
+                for (ExceptionProxyObject obj : idList) {
                     buf.append(obj.getDescription());
                     buf.append(":");
                     buf.append(obj.getUuid());
@@ -401,10 +406,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 s_logger.info("PermissionDenied: " + ex.getMessage());
             }
             throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, ex.getMessage(), ex);
-        } catch (final AccountLimitException ex) {
+        } catch (AccountLimitException ex) {
             s_logger.info(ex.getMessage());
             throw new ServerApiException(ApiErrorCode.ACCOUNT_RESOURCE_LIMIT_ERROR, ex.getMessage(), ex);
-        } catch (final InsufficientCapacityException ex) {
+        } catch (InsufficientCapacityException ex) {
             s_logger.info(ex.getMessage());
             String errorMsg = ex.getMessage();
             if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN) {
@@ -412,10 +417,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 errorMsg = BaseCmd.USER_ERROR_MESSAGE;
             }
             throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, errorMsg, ex);
-        } catch (final ResourceAllocationException ex) {
+        } catch (ResourceAllocationException ex) {
             s_logger.info(ex.getMessage());
             throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage(), ex);
-        } catch (final ResourceUnavailableException ex) {
+        } catch (ResourceUnavailableException ex) {
             s_logger.info(ex.getMessage());
             String errorMsg = ex.getMessage();
             if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN) {
@@ -423,11 +428,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 errorMsg = BaseCmd.USER_ERROR_MESSAGE;
             }
             throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, errorMsg, ex);
-        } catch (final ServerApiException ex) {
+        } catch (ServerApiException ex) {
             s_logger.info(ex.getDescription());
             throw ex;
-        } catch (final Exception ex) {
-            s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command), ex);
+        } catch (Exception ex) {
+            s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex);
             String errorMsg = ex.getMessage();
             if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN) {
                 // hide internal details to non-admin user for security reason
@@ -439,28 +444,28 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         return response;
     }
 
-    private String getBaseAsyncResponse(final long jobId, final BaseAsyncCmd cmd) {
-        final AsyncJobResponse response = new AsyncJobResponse();
+    private String getBaseAsyncResponse(long jobId, BaseAsyncCmd cmd) {
+        AsyncJobResponse response = new AsyncJobResponse();
 
-        final AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
+        AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
         response.setJobId(job.getUuid());
         response.setResponseName(cmd.getCommandName());
         return ApiResponseSerializer.toSerializedString(response, cmd.getResponseType());
     }
 
-    private String getBaseAsyncCreateResponse(final long jobId, final BaseAsyncCreateCmd cmd, final String objectUuid) {
-        final CreateCmdResponse response = new CreateCmdResponse();
-        final AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
+    private String getBaseAsyncCreateResponse(long jobId, BaseAsyncCreateCmd cmd, String objectUuid) {
+        CreateCmdResponse response = new CreateCmdResponse();
+        AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
         response.setJobId(job.getUuid());
         response.setId(objectUuid);
         response.setResponseName(cmd.getCommandName());
         return ApiResponseSerializer.toSerializedString(response, cmd.getResponseType());
     }
 
-    private String queueCommand(final BaseCmd cmdObj, final Map<String, Object> params) throws Exception {
-        final CallContext ctx = CallContext.current();
-        final Long callerUserId = ctx.getCallingUserId();
-        final Account caller = ctx.getCallingAccount();
+    private String queueCommand(BaseCmd cmdObj, Map<String, String> params) throws Exception {
+        CallContext ctx = CallContext.current();
+        Long callerUserId = ctx.getCallingUserId();
+        Account caller = ctx.getCallingAccount();
 
         // Queue command based on Cmd super class:
         // BaseCmd: cmd is dispatched to ApiDispatcher, executed, serialized and returned.
@@ -470,16 +475,16 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             Long objectId = null;
             String objectUuid = null;
             if (cmdObj instanceof BaseAsyncCreateCmd) {
-                final BaseAsyncCreateCmd createCmd = (BaseAsyncCreateCmd)cmdObj;
+                BaseAsyncCreateCmd createCmd = (BaseAsyncCreateCmd)cmdObj;
                 _dispatcher.dispatchCreateCmd(createCmd, params);
                 objectId = createCmd.getEntityId();
                 objectUuid = createCmd.getEntityUuid();
                 params.put("id", objectId.toString());
             } else {
-                dispatchChainFactory.getStandardDispatchChain().dispatch(cmdObj, params);
+                ApiDispatcher.processParameters(cmdObj, params);
             }
 
-            final BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmdObj;
+            BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmdObj;
 
             if (callerUserId != null) {
                 params.put("ctxUserId", callerUserId.toString());
@@ -492,7 +497,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             asyncCmd.setStartEventId(startEventId);
 
             // save the scheduled event
-            final Long eventId =
+            Long eventId =
                 ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(),
                     asyncCmd.getEventDescription(), startEventId);
             if (startEventId == 0) {
@@ -503,22 +508,22 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             params.put("ctxStartEventId", String.valueOf(startEventId));
             params.put("cmdEventType", asyncCmd.getEventType().toString());
 
-            final Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
-            final AsyncJobVO job =
+            Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
+            AsyncJobVO job =
                 new AsyncJobVO(ctx.getContextId(), callerUserId, caller.getId(), cmdObj.getClass().getName(), ApiGsonHelper.getBuilder().create().toJson(params),
                     instanceId, asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null);
             job.setDispatcher(_asyncDispatcher.getName());
 
-            final long jobId = _asyncMgr.submitAsyncJob(job);
+            long jobId = _asyncMgr.submitAsyncJob(job);
 
             if (jobId == 0L) {
-                final String errorMsg = "Unable to schedule async job for command " + job.getCmd();
+                String errorMsg = "Unable to schedule async job for command " + job.getCmd();
                 s_logger.warn(errorMsg);
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg);
             }
 
             if (objectId != null) {
-                final String objUuid = (objectUuid == null) ? objectId.toString() : objectUuid;
+                String objUuid = (objectUuid == null) ? objectId.toString() : objectUuid;
                 return getBaseAsyncCreateResponse(jobId, (BaseAsyncCreateCmd)asyncCmd, objUuid);
             } else {
                 SerializationContext.current().setUuidTranslation(true);
@@ -545,8 +550,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @SuppressWarnings("unchecked")
-    private void buildAsyncListResponse(final BaseListCmd command, final Account account) {
-        final List<ResponseObject> responses = ((ListResponse)command.getResponseObject()).getResponses();
+    private void buildAsyncListResponse(BaseListCmd command, Account account) {
+        List<ResponseObject> responses = ((ListResponse)command.getResponseObject()).getResponses();
         if (responses != null && responses.size() > 0) {
             List<? extends AsyncJob> jobs = null;
 
@@ -561,18 +566,18 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 return;
             }
 
-            final Map<String, AsyncJob> objectJobMap = new HashMap<String, AsyncJob>();
-            for (final AsyncJob job : jobs) {
+            Map<String, AsyncJob> objectJobMap = new HashMap<String, AsyncJob>();
+            for (AsyncJob job : jobs) {
                 if (job.getInstanceId() == null) {
                     continue;
                 }
-                final String instanceUuid = ApiDBUtils.findJobInstanceUuid(job);
+                String instanceUuid = ApiDBUtils.findJobInstanceUuid(job);
                 objectJobMap.put(instanceUuid, job);
             }
 
-            for (final ResponseObject response : responses) {
+            for (ResponseObject response : responses) {
                 if (response.getObjectId() != null && objectJobMap.containsKey(response.getObjectId())) {
-                    final AsyncJob job = objectJobMap.get(response.getObjectId());
+                    AsyncJob job = objectJobMap.get(response.getObjectId());
                     response.setJobId(job.getUuid());
                     response.setJobStatus(job.getStatus().ordinal());
                 }
@@ -580,7 +585,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         }
     }
 
-    private void buildAuditTrail(final StringBuffer auditTrailSb, final String command, final String result) {
+    private void buildAuditTrail(StringBuffer auditTrailSb, String command, String result) {
         if (result == null) {
             return;
         }
@@ -593,31 +598,31 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Override
-    public boolean verifyRequest(final Map<String, Object[]> requestParameters, final Long userId) throws ServerApiException {
+    public boolean verifyRequest(Map<String, Object[]> requestParameters, Long userId) throws ServerApiException {
         try {
             String apiKey = null;
             String secretKey = null;
             String signature = null;
             String unsignedRequest = null;
 
-            final String[] command = (String[])requestParameters.get(ApiConstants.COMMAND);
+            String[] command = (String[])requestParameters.get("command");
             if (command == null) {
                 s_logger.info("missing command, ignoring request...");
                 return false;
             }
 
-            final String commandName = command[0];
+            String commandName = command[0];
 
             // if userId not null, that mean that user is logged in
             if (userId != null) {
-                final User user = ApiDBUtils.findUserById(userId);
+                User user = ApiDBUtils.findUserById(userId);
 
                 try {
                     checkCommandAvailable(user, commandName);
-                } catch (final RequestLimitException ex) {
+                } catch (RequestLimitException ex) {
                     s_logger.debug(ex.getMessage());
                     throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
-                } catch (final PermissionDeniedException ex) {
+                } catch (PermissionDeniedException ex) {
                     s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
                     throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
                 }
@@ -632,9 +637,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
             // - build a request string with sorted params, make sure it's all lowercase
             // - sign the request, verify the signature is the same
-            final List<String> parameterNames = new ArrayList<String>();
+            List<String> parameterNames = new ArrayList<String>();
 
-            for (final Object paramNameObj : requestParameters.keySet()) {
+            for (Object paramNameObj : requestParameters.keySet()) {
                 parameterNames.add((String)paramNameObj); // put the name in a list that we'll sort later
             }
 
@@ -643,9 +648,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             String signatureVersion = null;
             String expires = null;
 
-            for (final String paramName : parameterNames) {
+            for (String paramName : parameterNames) {
                 // parameters come as name/value pairs in the form String/String[]
-                final String paramValue = ((String[])requestParameters.get(paramName))[0];
+                String paramValue = ((String[])requestParameters.get(paramName))[0];
 
                 if ("signature".equalsIgnoreCase(paramName)) {
                     signature = paramValue;
@@ -683,30 +688,30 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 synchronized (DateFormatToUse) {
                     try {
                         expiresTS = DateFormatToUse.parse(expires);
-                    } catch (final ParseException pe) {
+                    } catch (ParseException pe) {
                         s_logger.debug("Incorrect date format for Expires parameter", pe);
                         return false;
                     }
                 }
-                final Date now = new Date(System.currentTimeMillis());
+                Date now = new Date(System.currentTimeMillis());
                 if (expiresTS.before(now)) {
                     s_logger.debug("Request expired -- ignoring ...sig: " + signature + ", apiKey: " + apiKey);
                     return false;
                 }
             }
 
-            final TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+            TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
             txn.close();
             User user = null;
             // verify there is a user with this api key
-            final Pair<User, Account> userAcctPair = _accountMgr.findUserByApiKey(apiKey);
+            Pair<User, Account> userAcctPair = _accountMgr.findUserByApiKey(apiKey);
             if (userAcctPair == null) {
                 s_logger.debug("apiKey does not map to a valid user -- ignoring request, apiKey: " + apiKey);
                 return false;
             }
 
             user = userAcctPair.first();
-            final Account account = userAcctPair.second();
+            Account account = userAcctPair.second();
 
             if (user.getState() != Account.State.enabled || !account.getState().equals(Account.State.enabled)) {
                 s_logger.info("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() +
@@ -716,10 +721,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
             try {
                 checkCommandAvailable(user, commandName);
-            } catch (final RequestLimitException ex) {
+            } catch (RequestLimitException ex) {
                 s_logger.debug(ex.getMessage());
                 throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
-            } catch (final PermissionDeniedException ex) {
+            } catch (PermissionDeniedException ex) {
                 s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user");
                 throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:"
                         + userId);
@@ -734,30 +739,30 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
             unsignedRequest = unsignedRequest.toLowerCase();
 
-            final Mac mac = Mac.getInstance("HmacSHA1");
-            final SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
+            Mac mac = Mac.getInstance("HmacSHA1");
+            SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
             mac.init(keySpec);
             mac.update(unsignedRequest.getBytes());
-            final byte[] encryptedBytes = mac.doFinal();
-            final String computedSignature = Base64.encodeBase64String(encryptedBytes);
-            final boolean equalSig = signature.equals(computedSignature);
+            byte[] encryptedBytes = mac.doFinal();
+            String computedSignature = Base64.encodeBase64String(encryptedBytes);
+            boolean equalSig = signature.equals(computedSignature);
             if (!equalSig) {
                 s_logger.info("User signature: " + signature + " is not equaled to computed signature: " + computedSignature);
             } else {
                 CallContext.register(user, account);
             }
             return equalSig;
-        } catch (final ServerApiException ex) {
+        } catch (ServerApiException ex) {
             throw ex;
-        } catch (final Exception ex) {
+        } catch (Exception ex) {
             s_logger.error("unable to verify request signature");
         }
         return false;
     }
 
     @Override
-    public Long fetchDomainId(final String domainUUID) {
-        final Domain domain = _domainMgr.getDomain(domainUUID);
+    public Long fetchDomainId(String domainUUID) {
+        Domain domain = _domainMgr.getDomain(domainUUID);
         if (domain != null)
             return domain.getId();
         else
@@ -765,15 +770,15 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Override
-    public void loginUser(final HttpSession session, final String username, final String password, Long domainId, final String domainPath, final String loginIpAddress,
-        final Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
+    public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, String loginIpAddress,
+        Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
         // We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist
         // we will default to ROOT
         if (domainId == null) {
             if (domainPath == null || domainPath.trim().length() == 0) {
                 domainId = Domain.ROOT_DOMAIN;
             } else {
-                final Domain domainObj = _domainMgr.findDomainByPath(domainPath);
+                Domain domainObj = _domainMgr.findDomainByPath(domainPath);
                 if (domainObj != null) {
                     domainId = domainObj.getId();
                 } else { // if an unknown path is passed in, fail the login call
@@ -782,26 +787,26 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             }
         }
 
-        final UserAccount userAcct = _accountMgr.authenticateUser(username, password, domainId, loginIpAddress, requestParameters);
+        UserAccount userAcct = _accountMgr.authenticateUser(username, password, domainId, loginIpAddress, requestParameters);
         if (userAcct != null) {
-            final String timezone = userAcct.getTimezone();
+            String timezone = userAcct.getTimezone();
             float offsetInHrs = 0f;
             if (timezone != null) {
-                final TimeZone t = TimeZone.getTimeZone(timezone);
+                TimeZone t = TimeZone.getTimeZone(timezone);
                 s_logger.info("Current user logged in under " + timezone + " timezone");
 
-                final java.util.Date date = new java.util.Date();
-                final long longDate = date.getTime();
-                final float offsetInMs = (t.getOffset(longDate));
+                java.util.Date date = new java.util.Date();
+                long longDate = date.getTime();
+                float offsetInMs = (t.getOffset(longDate));
                 offsetInHrs = offsetInMs / (1000 * 60 * 60);
                 s_logger.info("Timezone offset from UTC is: " + offsetInHrs);
             }
 
-            final Account account = _accountMgr.getAccount(userAcct.getAccountId());
+            Account account = _accountMgr.getAccount(userAcct.getAccountId());
 
             // set the userId and account object for everyone
             session.setAttribute("userid", userAcct.getId());
-            final UserVO user = (UserVO)_accountMgr.getActiveUser(userAcct.getId());
+            UserVO user = (UserVO)_accountMgr.getActiveUser(userAcct.getId());
             if (user.getUuid() != null) {
                 session.setAttribute("user_UUID", user.getUuid());
             }
@@ -813,7 +818,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             session.setAttribute("account", account.getAccountName());
 
             session.setAttribute("domainid", account.getDomainId());
-            final DomainVO domain = (DomainVO)_domainMgr.getDomain(account.getDomainId());
+            DomainVO domain = (DomainVO)_domainMgr.getDomain(account.getDomainId());
             if (domain.getUuid() != null) {
                 session.setAttribute("domain_UUID", domain.getUuid());
             }
@@ -829,10 +834,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
             // (bug 5483) generate a session key that the user must submit on every request to prevent CSRF, add that
             // to the login response so that session-based authenticators know to send the key back
-            final SecureRandom sesssionKeyRandom = new SecureRandom();
-            final byte sessionKeyBytes[] = new byte[20];
+            SecureRandom sesssionKeyRandom = new SecureRandom();
+            byte sessionKeyBytes[] = new byte[20];
             sesssionKeyRandom.nextBytes(sessionKeyBytes);
-            final String sessionKey = Base64.encodeBase64String(sessionKeyBytes);
+            String sessionKey = Base64.encodeBase64String(sessionKeyBytes);
             session.setAttribute("sessionkey", sessionKey);
 
             return;
@@ -841,14 +846,14 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Override
-    public void logoutUser(final long userId) {
+    public void logoutUser(long userId) {
         _accountMgr.logoutUser(userId);
         return;
     }
 
     @Override
-    public boolean verifyUser(final Long userId) {
-        final User user = _accountMgr.getUserIncludingRemoved(userId);
+    public boolean verifyUser(Long userId) {
+        User user = _accountMgr.getUserIncludingRemoved(userId);
         Account account = null;
         if (user != null) {
             account = _accountMgr.getAccount(user.getAccountId());
@@ -862,27 +867,27 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         return true;
     }
 
-    private void checkCommandAvailable(final User user, final String commandName) throws PermissionDeniedException {
+    private void checkCommandAvailable(User user, String commandName) throws PermissionDeniedException {
         if (user == null) {
             throw new PermissionDeniedException("User is null for role based API access check for command" + commandName);
         }
 
-        for (final APIChecker apiChecker : _apiAccessCheckers) {
+        for (APIChecker apiChecker : _apiAccessCheckers) {
             apiChecker.checkAccess(user, commandName);
         }
     }
 
-    private Class<?> getCmdClass(final String cmdName) {
+    private Class<?> getCmdClass(String cmdName) {
         return s_apiNameCmdClassMap.get(cmdName);
     }
 
     // FIXME: rather than isError, we might was to pass in the status code to give more flexibility
-    private void writeResponse(final HttpResponse resp, final String responseText, final int statusCode, final String responseType, final String reasonPhrase) {
+    private void writeResponse(HttpResponse resp, final String responseText, final int statusCode, String responseType, String reasonPhrase) {
         try {
             resp.setStatusCode(statusCode);
             resp.setReasonPhrase(reasonPhrase);
 
-            final BasicHttpEntity body = new BasicHttpEntity();
+            BasicHttpEntity body = new BasicHttpEntity();
             if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
                 // JSON response
                 body.setContentType(jsonContentType);
@@ -900,7 +905,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 body.setContent(new ByteArrayInputStream(responseText.getBytes("UTF-8")));
             }
             resp.setEntity(body);
-        } catch (final Exception ex) {
+        } catch (Exception ex) {
             s_logger.error("error!", ex);
         }
     }
@@ -915,10 +920,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         private ServerSocket _serverSocket = null;
         private HttpParams _params = null;
 
-        public ListenerThread(final ApiServer requestHandler, final int port) {
+        public ListenerThread(ApiServer requestHandler, int port) {
             try {
                 _serverSocket = new ServerSocket(port);
-            } catch (final IOException ioex) {
+            } catch (IOException ioex) {
                 s_logger.error("error initializing api server", ioex);
                 return;
             }
@@ -931,14 +936,14 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                 .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
 
             // Set up the HTTP protocol processor
-            final BasicHttpProcessor httpproc = new BasicHttpProcessor();
+            BasicHttpProcessor httpproc = new BasicHttpProcessor();
             httpproc.addInterceptor(new ResponseDate());
             httpproc.addInterceptor(new ResponseServer());
             httpproc.addInterceptor(new ResponseContent());
             httpproc.addInterceptor(new ResponseConnControl());
 
             // Set up request handlers
-            final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
+            HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
             reqistry.register("*", requestHandler);
 
             // Set up the HTTP service
@@ -953,15 +958,15 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             while (!Thread.interrupted()) {
                 try {
                     // Set up HTTP connection
-                    final Socket socket = _serverSocket.accept();
-                    final DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
+                    Socket socket = _serverSocket.accept();
+                    DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
                     conn.bind(socket, _params);
 
                     // Execute a new worker task to handle the request
                     s_executor.execute(new WorkerTask(_httpService, conn, s_workerCount++));
-                } catch (final InterruptedIOException ex) {
+                } catch (InterruptedIOException ex) {
                     break;
-                } catch (final IOException e) {
+                } catch (IOException e) {
                     s_logger.error("I/O error initializing connection thread", e);
                     break;
                 }
@@ -980,33 +985,33 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
 
         @Override
         protected void runInContext() {
-            final HttpContext context = new BasicHttpContext(null);
+            HttpContext context = new BasicHttpContext(null);
             try {
                 while (!Thread.interrupted() && _conn.isOpen()) {
                     _httpService.handleRequest(_conn, context);
                     _conn.close();
                 }
-            } catch (final ConnectionClosedException ex) {
+            } catch (ConnectionClosedException ex) {
                 if (s_logger.isTraceEnabled()) {
                     s_logger.trace("ApiServer:  Client closed connection");
                 }
-            } catch (final IOException ex) {
+            } catch (IOException ex) {
                 if (s_logger.isTraceEnabled()) {
                     s_logger.trace("ApiServer:  IOException - " + ex);
                 }
-            } catch (final HttpException ex) {
+            } catch (HttpException ex) {
                 s_logger.warn("ApiServer:  Unrecoverable HTTP protocol violation" + ex);
             } finally {
                 try {
                     _conn.shutdown();
-                } catch (final IOException ignore) {
+                } catch (IOException ignore) {
                 }
             }
         }
     }
 
     @Override
-    public String getSerializedApiError(final int errorCode, final String errorText, final Map<String, Object[]> apiCommandParams, final String responseType) {
+    public String getSerializedApiError(int errorCode, String errorText, Map<String, Object[]> apiCommandParams, String responseType) {
         String responseName = null;
         Class<?> cmdClass = null;
         String responseText = null;
@@ -1015,10 +1020,10 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             if (apiCommandParams == null || apiCommandParams.isEmpty()) {
                 responseName = "errorresponse";
             } else {
-                final Object cmdObj = apiCommandParams.get(ApiConstants.COMMAND);
+                Object cmdObj = apiCommandParams.get("command");
                 // cmd name can be null when "command" parameter is missing in the request
                 if (cmdObj != null) {
-                    final String cmdName = ((String[])cmdObj)[0];
+                    String cmdName = ((String[])cmdObj)[0];
                     cmdClass = getCmdClass(cmdName);
                     if (cmdClass != null) {
                         responseName = ((BaseCmd)cmdClass.newInstance()).getCommandName();
@@ -1027,21 +1032,21 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                     }
                 }
             }
-            final ExceptionResponse apiResponse = new ExceptionResponse();
+            ExceptionResponse apiResponse = new ExceptionResponse();
             apiResponse.setErrorCode(errorCode);
             apiResponse.setErrorText(errorText);
             apiResponse.setResponseName(responseName);
             SerializationContext.current().setUuidTranslation(true);
             responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType);
 
-        } catch (final Exception e) {
+        } catch (Exception e) {
             s_logger.error("Exception responding to http request", e);
         }
         return responseText;
     }
 
     @Override
-    public String getSerializedApiError(final ServerApiException ex, final Map<String, Object[]> apiCommandParams, final String responseType) {
+    public String getSerializedApiError(ServerApiException ex, Map<String, Object[]> apiCommandParams, String responseType) {
         String responseName = null;
         Class<?> cmdClass = null;
         String responseText = null;
@@ -1054,11 +1059,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             if (ex.getErrorCode() == ApiErrorCode.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) {
                 responseName = "errorresponse";
             } else {
-                final Object cmdObj = apiCommandParams.get(ApiConstants.COMMAND);
+                Object cmdObj = apiCommandParams.get("command");
                 // cmd name can be null when "command" parameter is missing in
                 // the request
                 if (cmdObj != null) {
-                    final String cmdName = ((String[])cmdObj)[0];
+                    String cmdName = ((String[])cmdObj)[0];
                     cmdClass = getCmdClass(cmdName);
                     if (cmdClass != null) {
                         responseName = ((BaseCmd)cmdClass.newInstance()).getCommandName();
@@ -1067,11 +1072,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
                     }
                 }
             }
-            final ExceptionResponse apiResponse = new ExceptionResponse();
+            ExceptionResponse apiResponse = new ExceptionResponse();
             apiResponse.setErrorCode(ex.getErrorCode().getHttpCode());
             apiResponse.setErrorText(ex.getDescription());
             apiResponse.setResponseName(responseName);
-            final ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
+            ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
             if (idList != null) {
                 for (int i = 0; i < idList.size(); i++) {
                     apiResponse.addProxyObject(idList.get(i));
@@ -1084,7 +1089,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
             SerializationContext.current().setUuidTranslation(true);
             responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType);
 
-        } catch (final Exception e) {
+        } catch (Exception e) {
             s_logger.error("Exception responding to http request", e);
         }
         return responseText;
@@ -1095,7 +1100,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Inject
-    public void setPluggableServices(final List<PluggableService> pluggableServices) {
+    public void setPluggableServices(List<PluggableService> pluggableServices) {
         _pluggableServices = pluggableServices;
     }
 
@@ -1104,7 +1109,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
     }
 
     @Inject
-    public void setApiAccessCheckers(final List<APIChecker> apiAccessCheckers) {
+    public void setApiAccessCheckers(List<APIChecker> apiAccessCheckers) {
         _apiAccessCheckers = apiAccessCheckers;
     }
 
@@ -1112,7 +1117,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
         return encodeApiResponse;
     }
 
-    private static void setEncodeApiResponse(final boolean encodeApiResponse) {
+    private static void setEncodeApiResponse(boolean encodeApiResponse) {
         ApiServer.encodeApiResponse = encodeApiResponse;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index 901a0fd..46f7eba 100755
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -35,7 +35,6 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
 
-import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.ServerApiException;
@@ -68,40 +67,40 @@ public class ApiServlet extends HttpServlet {
     }
 
     @Override
-    public void init(final ServletConfig config) throws ServletException {
+    public void init(ServletConfig config) throws ServletException {
         SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
     }
 
     @Override
-    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
         processRequest(req, resp);
     }
 
     @Override
-    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) {
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
         processRequest(req, resp);
     }
 
-    private void utf8Fixup(final HttpServletRequest req, final Map<String, Object[]> params) {
+    private void utf8Fixup(HttpServletRequest req, Map<String, Object[]> params) {
         if (req.getQueryString() == null) {
             return;
         }
 
-        final String[] paramsInQueryString = req.getQueryString().split("&");
+        String[] paramsInQueryString = req.getQueryString().split("&");
         if (paramsInQueryString != null) {
-            for (final String param : paramsInQueryString) {
-                final String[] paramTokens = param.split("=", 2);
+            for (String param : paramsInQueryString) {
+                String[] paramTokens = param.split("=", 2);
                 if (paramTokens != null && paramTokens.length == 2) {
                     String name = paramTokens[0];
                     String value = paramTokens[1];
 
                     try {
                         name = URLDecoder.decode(name, "UTF-8");
-                    } catch (final UnsupportedEncodingException e) {
+                    } catch (UnsupportedEncodingException e) {
                     }
                     try {
                         value = URLDecoder.decode(value, "UTF-8");
-                    } catch (final UnsupportedEncodingException e) {
+                    } catch (UnsupportedEncodingException e) {
                     }
                     params.put(name, new String[] {value});
                 } else {
@@ -120,13 +119,13 @@ public class ApiServlet extends HttpServlet {
         });
     }
 
-    private void processRequestInContext(final HttpServletRequest req, final HttpServletResponse resp) {
-        final StringBuffer auditTrailSb = new StringBuffer();
+    private void processRequestInContext(HttpServletRequest req, HttpServletResponse resp) {
+        StringBuffer auditTrailSb = new StringBuffer();
         auditTrailSb.append(" " + req.getRemoteAddr());
         auditTrailSb.append(" -- " + req.getMethod() + " ");
         // get the response format since we'll need it in a couple of places
         String responseType = BaseCmd.RESPONSE_TYPE_XML;
-        final Map<String, Object[]> params = new HashMap<String, Object[]>();
+        Map<String, Object[]> params = new HashMap<String, Object[]>();
         params.putAll(req.getParameterMap());
 
         // For HTTP GET requests, it seems that HttpServletRequest.getParameterMap() actually tries
@@ -144,19 +143,19 @@ public class ApiServlet extends HttpServlet {
 
         try {
             HttpSession session = req.getSession(false);
-            final Object[] responseTypeParam = params.get(ApiConstants.RESPONSE);
+            Object[] responseTypeParam = params.get("response");
             if (responseTypeParam != null) {
                 responseType = (String)responseTypeParam[0];
             }
 
-            final Object[] commandParam = params.get(ApiConstants.COMMAND);
-            if (commandParam != null) {
-                final String command = (String)commandParam[0];
+            Object[] commandObj = params.get("command");
+            if (commandObj != null) {
+                String command = (String)commandObj[0];
                 if ("logout".equalsIgnoreCase(command)) {
                     // if this is just a logout, invalidate the session and return
                     if (session != null) {
-                        final Long userId = (Long)session.getAttribute("userid");
-                        final Account account = (Account)session.getAttribute("accountobj");
+                        Long userId = (Long)session.getAttribute("userid");
+                        Account account = (Account)session.getAttribute("accountobj");
                         Long accountId = null;
                         if (account != null) {
                             accountId = account.getId();
@@ -167,7 +166,7 @@ public class ApiServlet extends HttpServlet {
                         }
                         try {
                             session.invalidate();
-                        } catch (final IllegalStateException ise) {
+                        } catch (IllegalStateException ise) {
                         }
                     }
                     auditTrailSb.append("command=logout");
@@ -180,18 +179,18 @@ public class ApiServlet extends HttpServlet {
                     if (session != null) {
                         try {
                             session.invalidate();
-                        } catch (final IllegalStateException ise) {
+                        } catch (IllegalStateException ise) {
                         }
                     }
                     session = req.getSession(true);
-                    final String[] username = (String[])params.get(ApiConstants.USERNAME);
-                    final String[] password = (String[])params.get(ApiConstants.PASSWORD);
-                    String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
+                    String[] username = (String[])params.get("username");
+                    String[] password = (String[])params.get("password");
+                    String[] domainIdArr = (String[])params.get("domainid");
 
                     if (domainIdArr == null) {
-                        domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
+                        domainIdArr = (String[])params.get("domainId");
                     }
-                    final String[] domainName = (String[])params.get(ApiConstants.DOMAIN);
+                    String[] domainName = (String[])params.get("domain");
                     Long domainId = null;
                     if ((domainIdArr != null) && (domainIdArr.length > 0)) {
                         try {
@@ -201,10 +200,10 @@ public class ApiServlet extends HttpServlet {
                                 domainId = new Long(Long.parseLong(domainIdArr[0]));
                             }
                             auditTrailSb.append(" domainid=" + domainId);// building the params for POST call
-                        } catch (final NumberFormatException e) {
+                        } catch (NumberFormatException e) {
                             s_logger.warn("Invalid domain id entered by user");
                             auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "Invalid domain id entered, please enter a valid one");
-                            final String serializedResponse =
+                            String serializedResponse =
                                 _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid domain id entered, please enter a valid one", params,
                                     responseType);
                             writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
@@ -226,24 +225,24 @@ public class ApiServlet extends HttpServlet {
                     }
 
                     if (username != null) {
-                        final String pwd = ((password == null) ? null : password[0]);
+                        String pwd = ((password == null) ? null : password[0]);
                         try {
                             _apiServer.loginUser(session, username[0], pwd, domainId, domain, req.getRemoteAddr(), params);
                             auditTrailSb.insert(0, "(userId=" + session.getAttribute("userid") + " accountId=" + ((Account)session.getAttribute("accountobj")).getId() +
                                 " sessionId=" + session.getId() + ")");
-                            final String loginResponse = getLoginSuccessResponse(session, responseType);
+                            String loginResponse = getLoginSuccessResponse(session, responseType);
                             writeResponse(resp, loginResponse, HttpServletResponse.SC_OK, responseType);
                             return;
-                        } catch (final CloudAuthenticationException ex) {
+                        } catch (CloudAuthenticationException ex) {
                             // TODO: fall through to API key, or just fail here w/ auth error? (HTTP 401)
                             try {
                                 session.invalidate();
-                            } catch (final IllegalStateException ise) {
+                            } catch (IllegalStateException ise) {
                             }
 
                             auditTrailSb.append(" " + ApiErrorCode.ACCOUNT_ERROR + " " + ex.getMessage() != null ? ex.getMessage()
                                 : "failed to authenticate user, check if username/password are correct");
-                            final String serializedResponse =
+                            String serializedResponse =
                                 _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), ex.getMessage() != null ? ex.getMessage()
                                     : "failed to authenticate user, check if username/password are correct", params, responseType);
                             writeResponse(resp, serializedResponse, ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), responseType);
@@ -253,7 +252,7 @@ public class ApiServlet extends HttpServlet {
                 }
             }
             auditTrailSb.append(req.getQueryString());
-            final boolean isNew = ((session == null) ? true : session.isNew());
+            boolean isNew = ((session == null) ? true : session.isNew());
 
             // Initialize an empty context and we will update it after we have verified the request below,
             // we no longer rely on web-session here, verifyRequest will populate user/account information
@@ -262,17 +261,17 @@ public class ApiServlet extends HttpServlet {
 
             if (!isNew) {
                 userId = (Long)session.getAttribute("userid");
-                final String account = (String)session.getAttribute("account");
-                final Object accountObj = session.getAttribute("accountobj");
-                final String sessionKey = (String)session.getAttribute("sessionkey");
-                final String[] sessionKeyParam = (String[])params.get(ApiConstants.SESSIONKEY);
+                String account = (String)session.getAttribute("account");
+                Object accountObj = session.getAttribute("accountobj");
+                String sessionKey = (String)session.getAttribute("sessionkey");
+                String[] sessionKeyParam = (String[])params.get("sessionkey");
                 if ((sessionKeyParam == null) || (sessionKey == null) || !sessionKey.equals(sessionKeyParam[0])) {
                     try {
                         session.invalidate();
-                    } catch (final IllegalStateException ise) {
+                    } catch (IllegalStateException ise) {
                     }
                     auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
-                    final String serializedResponse =
+                    String serializedResponse =
                         _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType);
                     writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
                     return;
@@ -280,25 +279,26 @@ public class ApiServlet extends HttpServlet {
 
                 // Do a sanity check here to make sure the user hasn't already been deleted
                 if ((userId != null) && (account != null) && (accountObj != null) && _apiServer.verifyUser(userId)) {
-                    if (commandParam == null || commandParam[0] == null) {
+                    String[] command = (String[])params.get("command");
+                    if (command == null) {
                         s_logger.info("missing command, ignoring request...");
                         auditTrailSb.append(" " + HttpServletResponse.SC_BAD_REQUEST + " " + "no command specified");
-                        final String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType);
+                        String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType);
                         writeResponse(resp, serializedResponse, HttpServletResponse.SC_BAD_REQUEST, responseType);
                         return;
                     }
-                    final User user = _entityMgr.findById(User.class, userId);
+                    User user = _entityMgr.findById(User.class, userId);
                     CallContext.register(user, (Account)accountObj);
                 } else {
                     // Invalidate the session to ensure we won't allow a request across management server
                     // restarts if the userId was serialized to the stored session
                     try {
                         session.invalidate();
-                    } catch (final IllegalStateException ise) {
+                    } catch (IllegalStateException ise) {
                     }
 
                     auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
-                    final String serializedResponse =
+                    String serializedResponse =
                         _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType);
                     writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
                     return;
@@ -326,29 +326,29 @@ public class ApiServlet extends HttpServlet {
 
                 // Add the HTTP method (GET/POST/PUT/DELETE) as well into the params map.
                 params.put("httpmethod", new String[] {req.getMethod()});
-                final String response = _apiServer.handleRequest(params, responseType, auditTrailSb);
+                String response = _apiServer.handleRequest(params, responseType, auditTrailSb);
                 writeResponse(resp, response != null ? response : "", HttpServletResponse.SC_OK, responseType);
             } else {
                 if (session != null) {
                     try {
                         session.invalidate();
-                    } catch (final IllegalStateException ise) {
+                    } catch (IllegalStateException ise) {
                     }
                 }
 
                 auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials and/or request signature");
-                final String serializedResponse =
+                String serializedResponse =
                     _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params,
                         responseType);
                 writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
 
             }
-        } catch (final ServerApiException se) {
-            final String serializedResponseText = _apiServer.getSerializedApiError(se, params, responseType);
+        } catch (ServerApiException se) {
+            String serializedResponseText = _apiServer.getSerializedApiError(se, params, responseType);
             resp.setHeader("X-Description", se.getDescription());
             writeResponse(resp, serializedResponseText, se.getErrorCode().getHttpCode(), responseType);
             auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription());
-        } catch (final Exception ex) {
+        } catch (Exception ex) {
             s_logger.error("unknown exception writing api response", ex);
             auditTrailSb.append(" unknown exception writing api response");
         } finally {
@@ -372,7 +372,7 @@ public class ApiServlet extends HttpServlet {
      */
 
     // FIXME: rather than isError, we might was to pass in the status code to give more flexibility
-    private void writeResponse(final HttpServletResponse resp, final String response, final int responseCode, final String responseType) {
+    private void writeResponse(HttpServletResponse resp, String response, int responseCode, String responseType) {
         try {
             if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
                 resp.setContentType(ApiServer.getJsonContentType() + "; charset=UTF-8");
@@ -382,11 +382,11 @@ public class ApiServlet extends HttpServlet {
 
             resp.setStatus(responseCode);
             resp.getWriter().print(response);
-        } catch (final IOException ioex) {
+        } catch (IOException ioex) {
             if (s_logger.isTraceEnabled()) {
                 s_logger.trace("exception writing response: " + ioex);
             }
-        } catch (final Exception ex) {
+        } catch (Exception ex) {
             if (!(ex instanceof IllegalStateException)) {
                 s_logger.error("unknown exception writing api response", ex);
             }
@@ -394,29 +394,29 @@ public class ApiServlet extends HttpServlet {
     }
 
     @SuppressWarnings("rawtypes")
-    private String getLoginSuccessResponse(final HttpSession session, final String responseType) {
-        final StringBuffer sb = new StringBuffer();
-        final int inactiveInterval = session.getMaxInactiveInterval();
+    private String getLoginSuccessResponse(HttpSession session, String responseType) {
+        StringBuffer sb = new StringBuffer();
+        int inactiveInterval = session.getMaxInactiveInterval();
 
-        final String user_UUID = (String)session.getAttribute("user_UUID");
+        String user_UUID = (String)session.getAttribute("user_UUID");
         session.removeAttribute("user_UUID");
 
-        final String domain_UUID = (String)session.getAttribute("domain_UUID");
+        String domain_UUID = (String)session.getAttribute("domain_UUID");
         session.removeAttribute("domain_UUID");
 
         if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
             sb.append("{ \"loginresponse\" : { ");
-            final Enumeration attrNames = session.getAttributeNames();
+            Enumeration attrNames = session.getAttributeNames();
             if (attrNames != null) {
                 sb.append("\"timeout\" : \"" + inactiveInterval + "\"");
                 while (attrNames.hasMoreElements()) {
-                    final String attrName = (String)attrNames.nextElement();
+                    String attrName = (String)attrNames.nextElement();
                     if ("userid".equalsIgnoreCase(attrName)) {
                         sb.append(", \"" + attrName + "\" : \"" + user_UUID + "\"");
                     } else if ("domainid".equalsIgnoreCase(attrName)) {
                         sb.append(", \"" + attrName + "\" : \"" + domain_UUID + "\"");
                     } else {
-                        final Object attrObj = session.getAttribute(attrName);
+                        Object attrObj = session.getAttribute(attrName);
                         if ((attrObj instanceof String) || (attrObj instanceof Long)) {
                             sb.append(", \"" + attrName + "\" : \"" + attrObj.toString() + "\"");
                         }
@@ -428,16 +428,16 @@ public class ApiServlet extends HttpServlet {
             sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
             sb.append("<loginresponse cloud-stack-version=\"" + ApiDBUtils.getVersion() + "\">");
             sb.append("<timeout>" + inactiveInterval + "</timeout>");
-            final Enumeration attrNames = session.getAttributeNames();
+            Enumeration attrNames = session.getAttributeNames();
             if (attrNames != null) {
                 while (attrNames.hasMoreElements()) {
-                    final String attrName = (String)attrNames.nextElement();
+                    String attrName = (String)attrNames.nextElement();
                     if ("userid".equalsIgnoreCase(attrName)) {
                         sb.append("<" + attrName + ">" + user_UUID + "</" + attrName + ">");
                     } else if ("domainid".equalsIgnoreCase(attrName)) {
                         sb.append("<" + attrName + ">" + domain_UUID + "</" + attrName + ">");
                     } else {
-                        final Object attrObj = session.getAttribute(attrName);
+                        Object attrObj = session.getAttribute(attrName);
                         if (attrObj instanceof String || attrObj instanceof Long || attrObj instanceof Short) {
                             sb.append("<" + attrName + ">" + attrObj.toString() + "</" + attrName + ">");
                         }
@@ -450,8 +450,8 @@ public class ApiServlet extends HttpServlet {
         return sb.toString();
     }
 
-    private String getLogoutSuccessResponse(final String responseType) {
-        final StringBuffer sb = new StringBuffer();
+    private String getLogoutSuccessResponse(String responseType) {
+        StringBuffer sb = new StringBuffer();
         if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
             sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" } }");
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/ParameterHandler.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ParameterHandler.java b/server/src/com/cloud/api/ParameterHandler.java
deleted file mode 100644
index a9eb390..0000000
--- a/server/src/com/cloud/api/ParameterHandler.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;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.ServerApiException;
-
-public class ParameterHandler {
-
-    private static final Logger s_logger = Logger.getLogger(ParameterHandler.class.getName());
-
-    /**
-     * Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
-     */
-    public static final String CONTROL_CHARACTERS = "[\000-\011\013-\014\016-\037\177]";
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    public static Map<String, Object> unpackParams(final Map params) {
-        final Map<String, String> stringMap = new HashMap<String, String>();
-        final Set keys = params.keySet();
-        final Iterator keysIter = keys.iterator();
-        while (keysIter.hasNext()) {
-            final String key = (String)keysIter.next();
-            final String[] value = (String[])params.get(key);
-            // fail if parameter value contains ASCII control (non-printable) characters
-            if (value[0] != null) {
-                final Pattern pattern = Pattern.compile(CONTROL_CHARACTERS);
-                final Matcher matcher = pattern.matcher(value[0]);
-                if (matcher.find()) {
-                    throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Received value " + value[0] + " for parameter " + key +
-                        " is invalid, contains illegal ASCII non-printable characters");
-                }
-            }
-            stringMap.put(key, value[0]);
-        }
-
-        final Map<String, Object> lowercaseParams = new HashMap<String, Object>();
-        for (final Object keyObject : stringMap.keySet()) {
-            final String key = (String) keyObject;
-            final int arrayStartIndex = key.indexOf('[');
-            final int arrayStartLastIndex = key.lastIndexOf('[');
-            if (arrayStartIndex != arrayStartLastIndex) {
-                throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
-                    "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
-            }
-
-            if (arrayStartIndex > 0) {
-                final int arrayEndIndex = key.indexOf(']');
-                final int arrayEndLastIndex = key.lastIndexOf(']');
-                if ((arrayEndIndex < arrayStartIndex) || (arrayEndIndex != arrayEndLastIndex)) {
-                    // malformed parameter
-                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
-                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
-                }
-
-                // Now that we have an array object, check for a field name in the case of a complex object
-                final int fieldIndex = key.indexOf('.');
-                String fieldName = null;
-                if (fieldIndex < arrayEndIndex) {
-                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
-                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
-                } else {
-                    fieldName = key.substring(fieldIndex + 1);
-                }
-
-                // parse the parameter name as the text before the first '[' character
-                String paramName = key.substring(0, arrayStartIndex);
-                paramName = paramName.toLowerCase();
-
-                Map<Integer, Map> mapArray = null;
-                Map<String, Object> mapValue = null;
-                final String indexStr = key.substring(arrayStartIndex + 1, arrayEndIndex);
-                int index = 0;
-                boolean parsedIndex = false;
-                try {
-                    if (indexStr != null) {
-                        index = Integer.parseInt(indexStr);
-                        parsedIndex = true;
-                    }
-                } catch (final NumberFormatException nfe) {
-                    s_logger.warn("Invalid parameter " + key + " received, unable to parse object array, returning an error.");
-                }
-
-                if (!parsedIndex) {
-                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
-                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
-                }
-
-                final Object value = lowercaseParams.get(paramName);
-                if (value == null) {
-                    // for now, assume object array with sub fields
-                    mapArray = new HashMap<Integer, Map>();
-                    mapValue = new HashMap<String, Object>();
-                    mapArray.put(Integer.valueOf(index), mapValue);
-                } else if (value instanceof Map) {
-                    mapArray = (HashMap)value;
-                    mapValue = mapArray.get(Integer.valueOf(index));
-                    if (mapValue == null) {
-                        mapValue = new HashMap<String, Object>();
-                        mapArray.put(Integer.valueOf(index), mapValue);
-                    }
-                }
-
-                // we are ready to store the value for a particular field into the map for this object
-                mapValue.put(fieldName, stringMap.get(key));
-
-                lowercaseParams.put(paramName, mapArray);
-            } else {
-                lowercaseParams.put(key.toLowerCase(), stringMap.get(key));
-            }
-        }
-        return lowercaseParams;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/CommandCreationWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/CommandCreationWorker.java b/server/src/com/cloud/api/dispatch/CommandCreationWorker.java
deleted file mode 100644
index 3e11cc0..0000000
--- a/server/src/com/cloud/api/dispatch/CommandCreationWorker.java
+++ /dev/null
@@ -1,55 +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.dispatch;
-
-import java.util.Map;
-
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.ServerApiException;
-
-import com.cloud.exception.ResourceAllocationException;
-
-
-/**
- * This worker validates parameters in a semantic way, that is of
- * course specific for each {@link BaseCmd}, so actually it delegates
- * the validation on the {@link BaseCmd} itself
- *
- * @author afornie
- */
-public class CommandCreationWorker implements DispatchWorker {
-
-    @Override
-    public boolean handle(final BaseCmd cmd, final Map<String, Object> params) {
-        if (cmd instanceof BaseAsyncCreateCmd) {
-            try {
-                ((BaseAsyncCreateCmd)cmd).create();
-            } catch (final ResourceAllocationException e) {
-                throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR,
-                        e.getMessage(), e);
-            }
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
-                    "Trying to invoke creation on a Command that is not  BaseAsyncCreateCmd");
-        }
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/DispatchChain.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/DispatchChain.java b/server/src/com/cloud/api/dispatch/DispatchChain.java
deleted file mode 100644
index ecbb883..0000000
--- a/server/src/com/cloud/api/dispatch/DispatchChain.java
+++ /dev/null
@@ -1,45 +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.dispatch;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.ServerApiException;
-
-public class DispatchChain {
-
-    protected List<DispatchWorker> workers = new ArrayList<DispatchWorker>();
-
-    public DispatchChain add(final DispatchWorker worker) {
-        workers.add(worker);
-        return this;
-    }
-
-    public void dispatch(final BaseCmd cmd, final Map<String, Object> params)
-            throws ServerApiException {
-
-        for (final DispatchWorker worker : workers) {
-            if (!worker.handle(cmd, params)) {
-                break;
-            }
-        }
-    }
-}


[31/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
External UUID control: as only Root admin can change external UUID, so modified @Parameter to enforce the check


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e51d472b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e51d472b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e51d472b

Branch: refs/heads/rbac
Commit: e51d472b0cfda56db91fc82728c6bb29016e4d50
Parents: 4305d81
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Feb 5 15:28:34 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Feb 5 15:56:40 2014 -0800

----------------------------------------------------------------------
 api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java | 3 ++-
 api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java      | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e51d472b/api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java b/api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java
index dfb9439..b251c6e 100644
--- a/api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseAsyncCustomIdCmd.java
@@ -16,11 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api;
 
+import org.apache.cloudstack.acl.RoleType;
 
 public abstract class BaseAsyncCustomIdCmd extends BaseAsyncCmd {
     @Parameter(name = ApiConstants.CUSTOM_ID,
                type = CommandType.STRING,
- description = "an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only", since = "4.4")
+ description = "an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only", since = "4.4", authorized = {RoleType.Admin})
     private String customId;
 
     public String getCustomId() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e51d472b/api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java b/api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java
index 942f29f..7ca9f1e 100644
--- a/api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCustomIdCmd.java
@@ -16,11 +16,13 @@
 // under the License.
 package org.apache.cloudstack.api;
 
+import org.apache.cloudstack.acl.RoleType;
+
 public abstract class BaseCustomIdCmd extends BaseCmd {
 
     @Parameter(name = ApiConstants.CUSTOM_ID,
                type = CommandType.STRING,
- description = "an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only", since = "4.4")
+ description = "an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only", since = "4.4", authorized = {RoleType.Admin})
     private String customId;
 
     public String getCustomId() {


[10/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Removed some useless imports


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/03a424e4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/03a424e4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/03a424e4

Branch: refs/heads/rbac
Commit: 03a424e45abe753cd0227efb10eb21e2b9fab53c
Parents: 7f34282
Author: Alex Huang <al...@citrix.com>
Authored: Wed Jan 29 16:21:33 2014 +0000
Committer: Alex Huang <al...@citrix.com>
Committed: Wed Feb 5 01:39:16 2014 +0000

----------------------------------------------------------------------
 .../ConsoleProxyBalanceAllocator.java             |  3 ---
 .../consoleproxy/StaticConsoleProxyManager.java   | 18 ------------------
 2 files changed, 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03a424e4/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java b/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java
index 147063d..2cbd847 100644
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java
@@ -21,7 +21,6 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
@@ -32,8 +31,6 @@ import com.cloud.vm.ConsoleProxy;
 @Local(value = {ConsoleProxyAllocator.class})
 public class ConsoleProxyBalanceAllocator extends AdapterBase implements ConsoleProxyAllocator {
 
-    private final Random _rand = new Random(System.currentTimeMillis());
-
     @Override
     public Long allocProxy(List<? extends ConsoleProxy> candidates, final Map<Long, Integer> loadInfo, long dataCenterId) {
         List<ConsoleProxy> allocationList = new ArrayList<ConsoleProxy>(candidates);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03a424e4/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
index 27bdcbe..8aa9b0d 100755
--- a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
+++ b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
@@ -18,23 +18,17 @@ package com.cloud.consoleproxy;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.framework.security.keystore.KeystoreDao;
-import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
 
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupProxyCommand;
 import com.cloud.host.Host.Type;
 import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
 import com.cloud.info.ConsoleProxyInfo;
 import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceStateAdapter;
@@ -43,11 +37,9 @@ import com.cloud.resource.UnableDeleteHostException;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.dao.ConsoleProxyDao;
-import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = {ConsoleProxyManager.class})
 public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager implements ConsoleProxyManager, ResourceStateAdapter {
-    private static final Logger s_logger = Logger.getLogger(StaticConsoleProxyManager.class);
 
     @Inject
     ConsoleProxyDao _proxyDao;
@@ -55,16 +47,6 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp
     ResourceManager _resourceMgr;
     @Inject
     ConfigurationDao _configDao;
-    @Inject
-    private VMInstanceDao _instanceDao;
-    @Inject
-    KeystoreDao _ksDao;
-    @Inject
-    private KeystoreManager _ksMgr;
-    @Inject
-    private HostDao _hostDao;
-    private final Random _random = new Random(System.currentTimeMillis());
-    private String _hashKey;
     private String _ip = null;
 
     public StaticConsoleProxyManager() {


[44/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Revert "CLOUDSTACK-6003 fixing plus refactoring dispatcher" as it breaks API dispatching for commands having Map<String,String> as a parameter type

This reverts commit 447430c3df38c36d947c44c4aebd961d8cbb14c4.

Conflicts:
	api/src/org/apache/cloudstack/api/BaseCmd.java
	server/src/com/cloud/api/ApiDispatcher.java
	server/src/com/cloud/network/as/AutoScaleManagerImpl.java
	server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/782c5306
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/782c5306
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/782c5306

Branch: refs/heads/rbac
Commit: 782c53068564b96d11a09775d489a6e1b38adbd8
Parents: 9167286
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Thu Feb 6 14:34:43 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Thu Feb 6 14:46:58 2014 -0800

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |   5 -
 api/src/org/apache/cloudstack/api/BaseCmd.java  | 155 +++---
 .../org/apache/cloudstack/api/BaseListCmd.java  |  30 +-
 .../autoscale/CreateAutoScaleVmProfileCmd.java  |  30 +-
 .../core/spring-server-core-misc-context.xml    |  10 -
 .../com/cloud/api/ApiAsyncJobDispatcher.java    |  26 +-
 server/src/com/cloud/api/ApiDispatcher.java     | 485 +++++++++++++++++-
 server/src/com/cloud/api/ApiServer.java         | 345 ++++++-------
 server/src/com/cloud/api/ApiServlet.java        | 134 ++---
 server/src/com/cloud/api/ParameterHandler.java  | 138 ------
 .../api/dispatch/CommandCreationWorker.java     |  55 ---
 .../com/cloud/api/dispatch/DispatchChain.java   |  45 --
 .../api/dispatch/DispatchChainFactory.java      |  68 ---
 .../com/cloud/api/dispatch/DispatchWorker.java  |  34 --
 .../dispatch/ParamGenericValidationWorker.java  |  95 ----
 .../cloud/api/dispatch/ParamProcessWorker.java  | 429 ----------------
 .../dispatch/ParamSemanticValidationWorker.java |  40 --
 .../cloud/network/as/AutoScaleManagerImpl.java  | 490 +++++++++----------
 .../VirtualNetworkApplianceManagerImpl.java     |  14 +-
 .../storage/snapshot/SnapshotSchedulerImpl.java | 107 ++--
 .../test/com/cloud/api/ApiDispatcherTest.java   | 106 ++++
 .../api/dispatch/CommandCreationWorkerTest.java |  48 --
 .../api/dispatch/DispatchChainFactoryTest.java  |  54 --
 .../ParamGenericValidationWorkerTest.java       | 163 ------
 .../api/dispatch/ParamProcessWorkerTest.java    | 107 ----
 .../ParamSemanticValidationWorkerTest.java      |  48 --
 26 files changed, 1227 insertions(+), 2034 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 749a814..d500303 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -48,12 +48,10 @@ public class ApiConstants {
     public static final String CLUSTER_ID = "clusterid";
     public static final String CLUSTER_NAME = "clustername";
     public static final String CLUSTER_TYPE = "clustertype";
-    public static final String COMMAND = "command";
     public static final String COMPONENT = "component";
     public static final String CPU_NUMBER = "cpunumber";
     public static final String CPU_SPEED = "cpuspeed";
     public static final String CREATED = "created";
-    public static final String CTX_START_EVENT_ID = "ctxStartEventId";
     public static final String CUSTOMIZED = "customized";
     public static final String CUSTOMIZED_IOPS = "customizediops";
     public static final String CUSTOM_ID = "customid";
@@ -80,7 +78,6 @@ public class ApiConstants {
     public static final String IP6_DNS2 = "ip6dns2";
     public static final String DOMAIN = "domain";
     public static final String DOMAIN_ID = "domainid";
-    public static final String DOMAIN__ID = "domainId";
     public static final String DURATION = "duration";
     public static final String EMAIL = "email";
     public static final String END_DATE = "enddate";
@@ -211,7 +208,6 @@ public class ApiConstants {
     public static final String SENT = "sent";
     public static final String SENT_BYTES = "sentbytes";
     public static final String SERVICE_OFFERING_ID = "serviceofferingid";
-    public static final String SESSIONKEY = "sessionkey";
     public static final String SHOW_CAPACITIES = "showcapacities";
     public static final String SHOW_REMOVED = "showremoved";
     public static final String SIZE = "size";
@@ -280,7 +276,6 @@ public class ApiConstants {
     public static final String NETWORKRATE = "networkrate";
     public static final String HOST_TAGS = "hosttags";
     public static final String SSH_KEYPAIR = "keypair";
-    public static final String HTTPMETHOD = "httpmethod";
     public static final String HOST_CPU_CAPACITY = "hostcpucapacity";
     public static final String HOST_CPU_NUM = "hostcpunum";
     public static final String HOST_MEM_CAPACITY = "hostmemcapacity";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java
index 5b50153..0e83cee 100644
--- a/api/src/org/apache/cloudstack/api/BaseCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCmd.java
@@ -17,22 +17,17 @@
 
 package org.apache.cloudstack.api;
 
-import java.lang.reflect.Field;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
 
 import javax.inject.Inject;
 
-import org.apache.cloudstack.acl.RoleType;
 import org.apache.cloudstack.affinity.AffinityGroupService;
 import org.apache.cloudstack.alert.AlertService;
-import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
 import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
 import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
@@ -79,7 +74,6 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountService;
 import com.cloud.user.DomainService;
 import com.cloud.user.ResourceLimitService;
-import com.cloud.utils.ReflectUtil;
 import com.cloud.utils.db.EntityManager;
 import com.cloud.utils.db.UUIDManager;
 import com.cloud.vm.UserVmService;
@@ -103,8 +97,6 @@ public abstract class BaseCmd {
     public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+");
     private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
 
-    protected static final Map<Class<?>, List<Field>> fieldsForCmdClass = new HashMap<Class<?>, List<Field>>();
-
     private Object _responseObject = null;
     private Map<String, String> fullUrlParams;
 
@@ -213,7 +205,7 @@ public abstract class BaseCmd {
         return httpMethod;
     }
 
-    public void setHttpMethod(final String method) {
+    public void setHttpMethod(String method) {
         if (method != null) {
             if (method.equalsIgnoreCase("GET"))
                 httpMethod = HTTPMethod.GET;
@@ -235,7 +227,7 @@ public abstract class BaseCmd {
         return responseType;
     }
 
-    public void setResponseType(final String responseType) {
+    public void setResponseType(String responseType) {
         this.responseType = responseType;
     }
 
@@ -253,7 +245,7 @@ public abstract class BaseCmd {
         return _responseObject;
     }
 
-    public void setResponseObject(final Object responseObject) {
+    public void setResponseObject(Object responseObject) {
         _responseObject = responseObject;
     }
 
@@ -261,7 +253,7 @@ public abstract class BaseCmd {
         return _mgr;
     }
 
-    public static String getDateString(final Date date) {
+    public static String getDateString(Date date) {
         if (date == null) {
             return "";
         }
@@ -272,83 +264,101 @@ public abstract class BaseCmd {
         return formattedString;
     }
 
-    protected List<Field> getAllFieldsForClass(final Class<?> clazz) {
-        List<Field> filteredFields = fieldsForCmdClass.get(clazz);
+    // FIXME: move this to a utils method so that maps can be unpacked and integer/long values can be appropriately cast
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public Map<String, Object> unpackParams(Map<String, String> params) {
+        Map<String, Object> lowercaseParams = new HashMap<String, Object>();
+        for (String key : params.keySet()) {
+            int arrayStartIndex = key.indexOf('[');
+            int arrayStartLastIndex = key.lastIndexOf('[');
+            if (arrayStartIndex != arrayStartLastIndex) {
+                throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
+                    "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
+            }
 
-        // If list of fields was not cached yet
-        if (filteredFields == null) {
-            final List<Field> allFields = ReflectUtil.getAllFieldsForClass(this.getClass(), BaseCmd.class);
-            filteredFields = new ArrayList<Field>();
+            if (arrayStartIndex > 0) {
+                int arrayEndIndex = key.indexOf(']');
+                int arrayEndLastIndex = key.lastIndexOf(']');
+                if ((arrayEndIndex < arrayStartIndex) || (arrayEndIndex != arrayEndLastIndex)) {
+                    // malformed parameter
+                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
+                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
+                }
 
-            for (final Field field : allFields) {
-                final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
-                if ((parameterAnnotation != null) && parameterAnnotation.expose()) {
-                    filteredFields.add(field);
+                // Now that we have an array object, check for a field name in the case of a complex object
+                int fieldIndex = key.indexOf('.');
+                String fieldName = null;
+                if (fieldIndex < arrayEndIndex) {
+                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
+                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
+                } else {
+                    fieldName = key.substring(fieldIndex + 1);
                 }
-            }
 
-            // Cache the prepared list for future use
-            fieldsForCmdClass.put(clazz, filteredFields);
-        }
-        return filteredFields;
-    }
+                // parse the parameter name as the text before the first '[' character
+                String paramName = key.substring(0, arrayStartIndex);
+                paramName = paramName.toLowerCase();
+
+                Map<Integer, Map> mapArray = null;
+                Map<String, Object> mapValue = null;
+                String indexStr = key.substring(arrayStartIndex + 1, arrayEndIndex);
+                int index = 0;
+                boolean parsedIndex = false;
+                try {
+                    if (indexStr != null) {
+                        index = Integer.parseInt(indexStr);
+                        parsedIndex = true;
+                    }
+                } catch (NumberFormatException nfe) {
+                    s_logger.warn("Invalid parameter " + key + " received, unable to parse object array, returning an error.");
+                }
 
-    protected Account getCurrentContextAccount() {
-        return CallContext.current().getCallingAccount();
-    }
+                if (!parsedIndex) {
+                    throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key +
+                        "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup");
+                }
 
-    /**
-     * this method doesn't return all the @{link Parameter}, but only the ones exposed
-     * and allowed for current @{link RoleType}
-     *
-     * @return
-     */
-    public List<Field> getParamFields() {
-        final List<Field> allFields = getAllFieldsForClass(this.getClass());
-        final List<Field> validFields = new ArrayList<Field>();
-        final Account caller = getCurrentContextAccount();
-
-        for (final Field field : allFields) {
-            final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
-
-            //TODO: Annotate @Validate on API Cmd classes, FIXME how to process Validate
-            final RoleType[] allowedRoles = parameterAnnotation.authorized();
-            boolean roleIsAllowed = true;
-            if (allowedRoles.length > 0) {
-                roleIsAllowed = false;
-                for (final RoleType allowedRole : allowedRoles) {
-                    if (allowedRole.getValue() == caller.getType()) {
-                        roleIsAllowed = true;
-                        break;
+                Object value = lowercaseParams.get(paramName);
+                if (value == null) {
+                    // for now, assume object array with sub fields
+                    mapArray = new HashMap<Integer, Map>();
+                    mapValue = new HashMap<String, Object>();
+                    mapArray.put(Integer.valueOf(index), mapValue);
+                } else if (value instanceof Map) {
+                    mapArray = (HashMap)value;
+                    mapValue = mapArray.get(Integer.valueOf(index));
+                    if (mapValue == null) {
+                        mapValue = new HashMap<String, Object>();
+                        mapArray.put(Integer.valueOf(index), mapValue);
                     }
                 }
-            }
 
-            if (roleIsAllowed) {
-                validFields.add(field);
+                // we are ready to store the value for a particular field into the map for this object
+                mapValue.put(fieldName, params.get(key));
+
+                lowercaseParams.put(paramName, mapArray);
             } else {
-                s_logger.debug("Ignoring paremeter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in");
+                lowercaseParams.put(key.toLowerCase(), params.get(key));
             }
         }
-
-        return validFields;
+        return lowercaseParams;
     }
 
-    protected long getInstanceIdFromJobSuccessResult(final String result) {
+    protected long getInstanceIdFromJobSuccessResult(String result) {
         s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName());
         return 0;
     }
 
-    public static boolean isAdmin(final short accountType) {
+    public static boolean isAdmin(short accountType) {
         return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) ||
             (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
     }
 
-    public static boolean isRootAdmin(final short accountType) {
+    public static boolean isRootAdmin(short accountType) {
         return ((accountType == Account.ACCOUNT_TYPE_ADMIN));
     }
 
-    public void setFullUrlParams(final Map<String, String> map) {
+    public void setFullUrlParams(Map<String, String> map) {
         fullUrlParams = map;
     }
 
@@ -356,18 +366,18 @@ public abstract class BaseCmd {
         return fullUrlParams;
     }
 
-    public Long finalyzeAccountId(final String accountName, final Long domainId, final Long projectId, final boolean enabledOnly) {
+    public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
         if (accountName != null) {
             if (domainId == null) {
                 throw new InvalidParameterValueException("Account must be specified with domainId parameter");
             }
 
-            final Domain domain = _domainService.getDomain(domainId);
+            Domain domain = _domainService.getDomain(domainId);
             if (domain == null) {
                 throw new InvalidParameterValueException("Unable to find domain by id");
             }
 
-            final Account account = _accountService.getActiveAccountByName(accountName, domainId);
+            Account account = _accountService.getActiveAccountByName(accountName, domainId);
             if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
                 if (!enabledOnly || account.getState() == Account.State.enabled) {
                     return account.getId();
@@ -384,12 +394,12 @@ public abstract class BaseCmd {
         }
 
         if (projectId != null) {
-            final Project project = _projectService.getProject(projectId);
+            Project project = _projectService.getProject(projectId);
             if (project != null) {
                 if (!enabledOnly || project.getState() == Project.State.Active) {
                     return project.getProjectAccountId();
                 } else {
-                    final PermissionDeniedException ex =
+                    PermissionDeniedException ex =
                         new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() +
                             " as it's no longer active");
                     ex.addProxyObject(project.getUuid(), "projectId");
@@ -401,11 +411,4 @@ public abstract class BaseCmd {
         }
         return null;
     }
-
-    /**
-     * To be overwritten by any class who needs specific validation
-     */
-    public void validateSpecificParameters(final Map<String, Object> params){
-        // To be overwritten by any class who needs specific validation
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/api/src/org/apache/cloudstack/api/BaseListCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListCmd.java b/api/src/org/apache/cloudstack/api/BaseListCmd.java
index 1876995..c1a4b4c 100644
--- a/api/src/org/apache/cloudstack/api/BaseListCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseListCmd.java
@@ -16,10 +16,7 @@
 // under the License.
 package org.apache.cloudstack.api;
 
-import java.util.Map;
-
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.utils.exception.CSExceptionErrorCode;
 
 public abstract class BaseListCmd extends BaseCmd {
 
@@ -86,7 +83,7 @@ public abstract class BaseListCmd extends BaseCmd {
 
     public Long getPageSizeVal() {
         Long defaultPageSize = s_maxPageSize;
-        final Integer pageSizeInt = getPageSize();
+        Integer pageSizeInt = getPageSize();
         if (pageSizeInt != null) {
             defaultPageSize = pageSizeInt.longValue();
         }
@@ -99,12 +96,12 @@ public abstract class BaseListCmd extends BaseCmd {
 
     public Long getStartIndex() {
         Long startIndex = Long.valueOf(0);
-        final Long pageSizeVal = getPageSizeVal();
+        Long pageSizeVal = getPageSizeVal();
 
         if (pageSizeVal == null) {
             startIndex = null;
         } else if (page != null) {
-            final int pageNum = page.intValue();
+            int pageNum = page.intValue();
             if (pageNum > 0) {
                 startIndex = Long.valueOf(pageSizeVal * (pageNum - 1));
             }
@@ -115,25 +112,4 @@ public abstract class BaseListCmd extends BaseCmd {
     public ApiCommandJobType getInstanceType() {
         return ApiCommandJobType.None;
     }
-
-    @Override
-    public void validateSpecificParameters(final Map<String, Object> params){
-        super.validateSpecificParameters(params);
-
-        final Object pageSizeObj = params.get(ApiConstants.PAGE_SIZE);
-        Long pageSize = null;
-        if (pageSizeObj != null) {
-            pageSize = Long.valueOf((String)pageSizeObj);
-        }
-
-        if (params.get(ApiConstants.PAGE) == null &&
-                pageSize != null &&
-                !pageSize.equals(BaseListCmd.s_pageSizeUnlimited)) {
-            final ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
-            ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
-            throw ex;
-        } else if (pageSize == null && (params.get(ApiConstants.PAGE) != null)) {
-            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java
index ccdd557..bee1b22 100644
--- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java
@@ -151,7 +151,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
         }
         Account account = null;
         if (autoscaleUserId != null) {
-            final User user = _entityMgr.findById(User.class, autoscaleUserId);
+            User user = _entityMgr.findById(User.class, autoscaleUserId);
             account = _entityMgr.findById(Account.class, user.getAccountId());
         } else {
             account = CallContext.current().getCallingAccount();
@@ -167,21 +167,21 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
         }
         if (otherDeployParams == null)
             return;
-        final String[] keyValues = otherDeployParams.split("&"); // hostid=123, hypervisor=xenserver
-        for (final String keyValue : keyValues) { // keyValue == "hostid=123"
-            final String[] keyAndValue = keyValue.split("="); // keyValue = hostid, 123
+        String[] keyValues = otherDeployParams.split("&"); // hostid=123, hypervisor=xenserver
+        for (String keyValue : keyValues) { // keyValue == "hostid=123"
+            String[] keyAndValue = keyValue.split("="); // keyValue = hostid, 123
             if (keyAndValue.length != 2) {
                 throw new InvalidParameterValueException("Invalid parameter in otherDeployParam : " + keyValue);
             }
-            final String paramName = keyAndValue[0]; // hostid
-            final String paramValue = keyAndValue[1]; // 123
+            String paramName = keyAndValue[0]; // hostid
+            String paramValue = keyAndValue[1]; // 123
             otherDeployParamMap.put(paramName, paramValue);
         }
     }
 
-    public HashMap<String, Object> getDeployParamMap() {
+    public HashMap<String, String> getDeployParamMap() {
         createOtherDeployParamMap();
-        final HashMap<String, Object> deployParams = new HashMap<String, Object>(otherDeployParamMap);
+        HashMap<String, String> deployParams = new HashMap<String, String>(otherDeployParamMap);
         deployParams.put("command", "deployVirtualMachine");
         deployParams.put("zoneId", zoneId.toString());
         deployParams.put("serviceOfferingId", serviceOfferingId.toString());
@@ -189,7 +189,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
         return deployParams;
     }
 
-    public String getOtherDeployParam(final String param) {
+    public String getOtherDeployParam(String param) {
         if (param == null) {
             return null;
         }
@@ -232,19 +232,19 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void execute() {
-        final AutoScaleVmProfile result = _entityMgr.findById(AutoScaleVmProfile.class, getEntityId());
-        final AutoScaleVmProfileResponse response = _responseGenerator.createAutoScaleVmProfileResponse(result);
+        AutoScaleVmProfile result = _entityMgr.findById(AutoScaleVmProfile.class, getEntityId());
+        AutoScaleVmProfileResponse response = _responseGenerator.createAutoScaleVmProfileResponse(result);
         response.setResponseName(getCommandName());
-        setResponseObject(response);
+        this.setResponseObject(response);
     }
 
     @Override
     public void create() throws ResourceAllocationException {
 
-        final AutoScaleVmProfile result = _autoScaleService.createAutoScaleVmProfile(this);
+        AutoScaleVmProfile result = _autoScaleService.createAutoScaleVmProfile(this);
         if (result != null) {
-            setEntityId(result.getId());
-            setEntityUuid(result.getUuid());
+            this.setEntityId(result.getId());
+            this.setEntityUuid(result.getUuid());
         } else {
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Profile");
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml
----------------------------------------------------------------------
diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml
index f35ee5e..fd2f5fb 100644
--- a/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml
+++ b/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml
@@ -50,16 +50,6 @@
 
     <bean id="apiDispatcher" class="com.cloud.api.ApiDispatcher" />
 
-    <bean id="dispatchChainFactory" class="com.cloud.api.dispatch.DispatchChainFactory" />
-
-    <bean id="paramSemanticValidationWorker" class="com.cloud.api.dispatch.ParamSemanticValidationWorker" />
-
-    <bean id="paramProcessWorker" class="com.cloud.api.dispatch.ParamProcessWorker" />
-
-    <bean id="paramGenericValidationWorker" class="com.cloud.api.dispatch.ParamGenericValidationWorker" />
-
-    <bean id="commandCreationWorker" class="com.cloud.api.dispatch.CommandCreationWorker" />
-
     <bean id="apiResponseHelper" class="com.cloud.api.ApiResponseHelper" />
 
     <bean id="apiServer" class="com.cloud.api.ApiServer">

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/ApiAsyncJobDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java
index 565e3a4..71ac616 100644
--- a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java
+++ b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java
@@ -70,30 +70,30 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat
         });
     }
 
-    protected void runJobInContext(final AsyncJob job) {
+    protected void runJobInContext(AsyncJob job) {
         BaseAsyncCmd cmdObj = null;
         try {
-            final Class<?> cmdClass = Class.forName(job.getCmd());
+            Class<?> cmdClass = Class.forName(job.getCmd());
             cmdObj = (BaseAsyncCmd)cmdClass.newInstance();
             cmdObj = ComponentContext.inject(cmdObj);
             cmdObj.configure();
             cmdObj.setJob(job);
 
-            final Type mapType = new TypeToken<Map<String, String>>() {
+            Type mapType = new TypeToken<Map<String, String>>() {
             }.getType();
-            final Gson gson = ApiGsonHelper.getBuilder().create();
-            final Map<String, Object> params = gson.fromJson(job.getCmdInfo(), mapType);
+            Gson gson = ApiGsonHelper.getBuilder().create();
+            Map<String, String> params = gson.fromJson(job.getCmdInfo(), mapType);
 
             // whenever we deserialize, the UserContext needs to be updated
-            final String userIdStr = (String) params.get("ctxUserId");
-            final String acctIdStr = (String) params.get("ctxAccountId");
+            String userIdStr = params.get("ctxUserId");
+            String acctIdStr = params.get("ctxAccountId");
             Long userId = null;
             Account accountObject = null;
 
             if (cmdObj instanceof BaseAsyncCreateCmd) {
-                final BaseAsyncCreateCmd create = (BaseAsyncCreateCmd)cmdObj;
-                create.setEntityId(Long.parseLong((String) params.get("id")));
-                create.setEntityUuid((String) params.get("uuid"));
+                BaseAsyncCreateCmd create = (BaseAsyncCreateCmd)cmdObj;
+                create.setEntityId(Long.parseLong(params.get("id")));
+                create.setEntityUuid(params.get("uuid"));
             }
 
             User user = null;
@@ -116,19 +116,19 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat
             } finally {
                 CallContext.unregister();
             }
-        } catch (final Throwable e) {
+        } catch (Throwable e) {
             String errorMsg = null;
             int errorCode = ApiErrorCode.INTERNAL_ERROR.getHttpCode();
             if (!(e instanceof ServerApiException)) {
                 s_logger.error("Unexpected exception while executing " + job.getCmd(), e);
                 errorMsg = e.getMessage();
             } else {
-                final ServerApiException sApiEx = (ServerApiException)e;
+                ServerApiException sApiEx = (ServerApiException)e;
                 errorMsg = sApiEx.getDescription();
                 errorCode = sApiEx.getErrorCode().getHttpCode();
             }
 
-            final ExceptionResponse response = new ExceptionResponse();
+            ExceptionResponse response = new ExceptionResponse();
             response.setErrorCode(errorCode);
             response.setErrorText(errorMsg);
             response.setResponseName((cmdObj == null) ? "unknowncommandresponse" : cmdObj.getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index 7d9b7d7..ed95c72 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -16,67 +16,126 @@
 // under the License.
 package com.cloud.api;
 
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
+import java.lang.reflect.Field;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.InfrastructureEntity;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.ACL;
 import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.BaseAsyncCreateCmd;
 import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseCmd.CommandType;
 import org.apache.cloudstack.api.BaseCustomIdCmd;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
+import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
+import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
+import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
+import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.jobs.AsyncJob;
 import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.log4j.Logger;
 
-import com.cloud.api.dispatch.DispatchChain;
-import com.cloud.api.dispatch.DispatchChainFactory;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.ReflectUtil;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.utils.exception.CSExceptionErrorCode;
+import com.cloud.utils.exception.CloudRuntimeException;
 
 public class ApiDispatcher {
     private static final Logger s_logger = Logger.getLogger(ApiDispatcher.class.getName());
 
     Long _createSnapshotQueueSizeLimit;
-
     @Inject
     AsyncJobManager _asyncMgr = null;
+    @Inject
+    AccountManager _accountMgr = null;
+    @Inject
+    EntityManager _entityMgr = null;
 
-    @Inject()
-    protected DispatchChainFactory dispatchChainFactory = null;
-
-    protected DispatchChain standardDispatchChain = null;
+    private static ApiDispatcher s_instance;
 
-    protected DispatchChain asyncCreationDispatchChain = null;
+    public static ApiDispatcher getInstance() {
+        return s_instance;
+    }
 
     public ApiDispatcher() {
     }
 
     @PostConstruct
-    public void setup() {
-        standardDispatchChain = dispatchChainFactory.getStandardDispatchChain();
-        asyncCreationDispatchChain = dispatchChainFactory.getAsyncCreationDispatchChain();
+    void init() {
+        s_instance = this;
     }
 
-    public void setCreateSnapshotQueueSizeLimit(final Long snapshotLimit) {
+    public void setCreateSnapshotQueueSizeLimit(Long snapshotLimit) {
         _createSnapshotQueueSizeLimit = snapshotLimit;
     }
 
-    public void dispatchCreateCmd(final BaseAsyncCreateCmd cmd, final Map<String, Object> params) throws Exception {
-        asyncCreationDispatchChain.dispatch(cmd, params);
+    public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) throws Exception {
+        processParameters(cmd, params);
+
+        cmd.create();
+
     }
 
-    public void dispatch(final BaseCmd cmd, final Map<String, Object> params, final boolean execute) throws Exception {
-        // Let the chain of responsibility dispatch gradually
-        standardDispatchChain.dispatch(cmd, params);
+    private void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess) {
+        Account caller = CallContext.current().getCallingAccount();
+        Account owner = _accountMgr.getActiveAccountById(cmd.getEntityOwnerId());
 
-        final CallContext ctx = CallContext.current();
+        if (cmd instanceof BaseAsyncCreateCmd) {
+            //check that caller can access the owner account.
+            _accountMgr.checkAccess(caller, null, true, owner);
+        }
+
+        if (!entitiesToAccess.isEmpty()) {
+            //check that caller can access the owner account.
+            _accountMgr.checkAccess(caller, null, true, owner);
+            for (Object entity : entitiesToAccess.keySet()) {
+                if (entity instanceof ControlledEntity) {
+                    _accountMgr.checkAccess(caller, entitiesToAccess.get(entity), true, (ControlledEntity)entity);
+                } else if (entity instanceof InfrastructureEntity) {
+                    //FIXME: Move this code in adapter, remove code from Account manager
+                }
+            }
+        }
+    }
+
+    public void dispatch(BaseCmd cmd, Map<String, String> params, boolean execute) throws Exception {
+        processParameters(cmd, params);
+        CallContext ctx = CallContext.current();
 
         if (cmd instanceof BaseAsyncCmd) {
 
-            final BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd;
-            final String startEventId = (String) params.get(ApiConstants.CTX_START_EVENT_ID);
+            BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd;
+            String startEventId = params.get("ctxStartEventId");
             ctx.setStartEventId(Long.valueOf(startEventId));
 
             // Synchronise job on the object if needed
@@ -107,6 +166,392 @@ public class ApiDispatcher {
         }
 
         cmd.execute();
+
     }
 
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public static void processParameters(BaseCmd cmd, Map<String, String> params) {
+        Map<Object, AccessType> entitiesToAccess = new HashMap<Object, AccessType>();
+        Map<String, Object> unpackedParams = cmd.unpackParams(params);
+
+        if (cmd instanceof BaseListCmd) {
+            Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
+            Long pageSize = null;
+            if (pageSizeObj != null) {
+                pageSize = Long.valueOf((String)pageSizeObj);
+            }
+
+            if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && !pageSize.equals(BaseListCmd.s_pageSizeUnlimited))) {
+                ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
+                ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
+                throw ex;
+            } else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
+                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
+            }
+        }
+
+        List<Field> fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), BaseCmd.class);
+
+        for (Field field : fields) {
+            Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
+            if ((parameterAnnotation == null) || !parameterAnnotation.expose()) {
+                continue;
+            }
+
+            //TODO: Annotate @Validate on API Cmd classes, FIXME how to process Validate
+            RoleType[] allowedRoles = parameterAnnotation.authorized();
+            if (allowedRoles.length > 0) {
+                boolean permittedParameter = false;
+                Account caller = CallContext.current().getCallingAccount();
+                for (RoleType allowedRole : allowedRoles) {
+                    if (allowedRole.getValue() == caller.getType()) {
+                        permittedParameter = true;
+                        break;
+                    }
+                }
+                if (!permittedParameter) {
+                    s_logger.debug("Ignoring paremeter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in");
+                    continue;
+                }
+            }
+
+            Object paramObj = unpackedParams.get(parameterAnnotation.name());
+            if (paramObj == null) {
+                if (parameterAnnotation.required()) {
+                    throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
+                        cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter " + parameterAnnotation.name());
+                }
+                continue;
+            }
+
+            // marshall the parameter into the correct type and set the field value
+            try {
+                setFieldValue(field, cmd, paramObj, parameterAnnotation);
+            } catch (IllegalArgumentException argEx) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " +
+                        parameterAnnotation.name());
+                }
+                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
+                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
+                    parameterAnnotation.name());
+            } catch (ParseException parseEx) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
+                }
+                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
+                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
+            } catch (InvalidParameterValueException invEx) {
+                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
+                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
+            } catch (CloudRuntimeException cloudEx) {
+                s_logger.error("CloudRuntimeException", cloudEx);
+                // FIXME: Better error message? This only happens if the API command is not executable, which typically
+                //means
+                // there was
+                // and IllegalAccessException setting one of the parameters.
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
+                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
+            }
+
+            //check access on the resource this field points to
+            try {
+                ACL checkAccess = field.getAnnotation(ACL.class);
+                CommandType fieldType = parameterAnnotation.type();
+
+                if (checkAccess != null) {
+                    // Verify that caller can perform actions in behalf of vm owner
+                    //acumulate all Controlled Entities together.
+
+                    //parse the array of resource types and in case of map check access on key or value or both as specified in @acl
+                    //implement external dao for classes that need findByName
+                    //for maps, specify access to be checkd on key or value.
+
+                    // find the controlled entity DBid by uuid
+                    if (parameterAnnotation.entityType() != null) {
+                        Class<?>[] entityList = parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class).value();
+
+                        for (Class entity : entityList) {
+                            // Check if the parameter type is a single
+                            // Id or list of id's/name's
+                            switch (fieldType) {
+                                case LIST:
+                                    CommandType listType = parameterAnnotation.collectionType();
+                                    switch (listType) {
+                                        case LONG:
+                                        case UUID:
+                                            List<Long> listParam = (List<Long>)field.get(cmd);
+                                            for (Long entityId : listParam) {
+                                                Object entityObj = s_instance._entityMgr.findById(entity, entityId);
+                                                entitiesToAccess.put(entityObj, checkAccess.accessType());
+                                            }
+                                            break;
+                                        /*
+                                         * case STRING: List<String> listParam =
+                                         * new ArrayList<String>(); listParam =
+                                         * (List)field.get(cmd); for(String
+                                         * entityName: listParam){
+                                         * ControlledEntity entityObj =
+                                         * (ControlledEntity
+                                         * )daoClassInstance(entityId);
+                                         * entitiesToAccess.add(entityObj); }
+                                         * break;
+                                         */
+                                        default:
+                                            break;
+                                    }
+                                    break;
+                                case LONG:
+                                case UUID:
+                                    Object entityObj = s_instance._entityMgr.findById(entity, (Long)field.get(cmd));
+                                    entitiesToAccess.put(entityObj, checkAccess.accessType());
+                                    break;
+                                default:
+                                    break;
+                            }
+
+                            if (ControlledEntity.class.isAssignableFrom(entity)) {
+                                if (s_logger.isDebugEnabled()) {
+                                    s_logger.debug("ControlledEntity name is:" + entity.getName());
+                                }
+                            }
+
+                            if (InfrastructureEntity.class.isAssignableFrom(entity)) {
+                                if (s_logger.isDebugEnabled()) {
+                                    s_logger.debug("InfrastructureEntity name is:" + entity.getName());
+                                }
+                            }
+                        }
+
+                    }
+
+                }
+
+            } catch (IllegalArgumentException e) {
+                s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
+                throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
+                    " is not accessible]");
+            } catch (IllegalAccessException e) {
+                s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
+                throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
+                    " is not accessible]");
+            }
+
+        }
+
+        //check access on the entities.
+        getInstance().doAccessChecks(cmd, entitiesToAccess);
+
+    }
+
+    private static Long translateUuidToInternalId(String uuid, Parameter annotation) {
+        if (uuid.equals("-1")) {
+            // FIXME: This is to handle a lot of hardcoded special cases where -1 is sent
+            // APITODO: Find and get rid of all hardcoded params in API Cmds and service layer
+            return -1L;
+        }
+        Long internalId = null;
+        // If annotation's empty, the cmd existed before 3.x try conversion to long
+        boolean isPre3x = annotation.since().isEmpty();
+        // Match against Java's UUID regex to check if input is uuid string
+        boolean isUuid = uuid.matches("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
+        // Enforce that it's uuid for newly added apis from version 3.x
+        if (!isPre3x && !isUuid)
+            return null;
+        // Allow both uuid and internal id for pre3x apis
+        if (isPre3x && !isUuid) {
+            try {
+                internalId = Long.parseLong(uuid);
+            } catch (NumberFormatException e) {
+                internalId = null;
+            }
+            if (internalId != null)
+                return internalId;
+        }
+        // There may be multiple entities defined on the @EntityReference of a Response.class
+        // UUID CommandType would expect only one entityType, so use the first entityType
+        Class<?>[] entities = annotation.entityType()[0].getAnnotation(EntityReference.class).value();
+        // Go through each entity which is an interface to a VO class and get a VO object
+        // Try to getId() for the object using reflection, break on first non-null value
+        for (Class<?> entity : entities) {
+            // For backward compatibility, we search within removed entities and let service layer deal
+            // with removed ones, return empty response or error
+            Object objVO = s_instance._entityMgr.findByUuidIncludingRemoved(entity, uuid);
+            if (objVO == null) {
+                continue;
+            }
+            // Invoke the getId method, get the internal long ID
+            // If that fails hide exceptions as the uuid may not exist
+            try {
+                internalId = ((InternalIdentity)objVO).getId();
+            } catch (IllegalArgumentException e) {
+            } catch (NullPointerException e) {
+            }
+            // Return on first non-null Id for the uuid entity
+            if (internalId != null)
+                break;
+        }
+        if (internalId == null) {
+            if (s_logger.isDebugEnabled())
+                s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
+            throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
+                " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
+        }
+        return internalId;
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    private static void setFieldValue(Field field, BaseCmd cmdObj, Object paramObj, Parameter annotation) throws IllegalArgumentException, ParseException {
+        try {
+            field.setAccessible(true);
+            CommandType fieldType = annotation.type();
+            switch (fieldType) {
+                case BOOLEAN:
+                    field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
+                    break;
+                case DATE:
+                    // This piece of code is for maintaining backward compatibility
+                    // and support both the date formats(Bug 9724)
+                    // Do the date messaging for ListEventsCmd only
+                    if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
+                        cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd) {
+                        boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
+                        if (isObjInNewDateFormat) {
+                            DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
+                            synchronized (newFormat) {
+                                field.set(cmdObj, newFormat.parse(paramObj.toString()));
+                            }
+                        } else {
+                            DateFormat format = BaseCmd.INPUT_FORMAT;
+                            synchronized (format) {
+                                Date date = format.parse(paramObj.toString());
+                                if (field.getName().equals("startDate")) {
+                                    date = messageDate(date, 0, 0, 0);
+                                } else if (field.getName().equals("endDate")) {
+                                    date = messageDate(date, 23, 59, 59);
+                                }
+                                field.set(cmdObj, date);
+                            }
+                        }
+                    } else {
+                        DateFormat format = BaseCmd.INPUT_FORMAT;
+                        synchronized (format) {
+                        format.setLenient(false);
+                            field.set(cmdObj, format.parse(paramObj.toString()));
+                        }
+                    }
+                    break;
+                case FLOAT:
+                    // Assuming that the parameters have been checked for required before now,
+                    // we ignore blank or null values and defer to the command to set a default
+                    // value for optional parameters ...
+                    if (paramObj != null && isNotBlank(paramObj.toString())) {
+                        field.set(cmdObj, Float.valueOf(paramObj.toString()));
+                    }
+                    break;
+                case INTEGER:
+                    // Assuming that the parameters have been checked for required before now,
+                    // we ignore blank or null values and defer to the command to set a default
+                    // value for optional parameters ...
+                    if (paramObj != null && isNotBlank(paramObj.toString())) {
+                        field.set(cmdObj, Integer.valueOf(paramObj.toString()));
+                    }
+                    break;
+                case LIST:
+                    List listParam = new ArrayList();
+                    StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
+                    while (st.hasMoreTokens()) {
+                        String token = st.nextToken();
+                        CommandType listType = annotation.collectionType();
+                        switch (listType) {
+                            case INTEGER:
+                                listParam.add(Integer.valueOf(token));
+                                break;
+                            case UUID:
+                                if (token.isEmpty())
+                                    break;
+                                Long internalId = translateUuidToInternalId(token, annotation);
+                                listParam.add(internalId);
+                                break;
+                            case LONG: {
+                                listParam.add(Long.valueOf(token));
+                            }
+                                break;
+                            case SHORT:
+                                listParam.add(Short.valueOf(token));
+                            case STRING:
+                                listParam.add(token);
+                                break;
+                        }
+                    }
+                    field.set(cmdObj, listParam);
+                    break;
+                case UUID:
+                    if (paramObj.toString().isEmpty())
+                        break;
+                    Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
+                    field.set(cmdObj, internalId);
+                    break;
+                case LONG:
+                    field.set(cmdObj, Long.valueOf(paramObj.toString()));
+                    break;
+                case SHORT:
+                    field.set(cmdObj, Short.valueOf(paramObj.toString()));
+                    break;
+                case STRING:
+                    if ((paramObj != null) && paramObj.toString().length() > annotation.length()) {
+                        s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
+                        throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
+                    }
+                    field.set(cmdObj, paramObj.toString());
+                    break;
+                case TZDATE:
+                    field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
+                    break;
+                case MAP:
+                default:
+                    field.set(cmdObj, paramObj);
+                    break;
+            }
+        } catch (IllegalAccessException ex) {
+            s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible.");
+            throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() +
+                " is not accessible]");
+        }
+    }
+
+    private static boolean isObjInNewDateFormat(String string) {
+        Matcher matcher = BaseCmd.newInputDateFormat.matcher(string);
+        return matcher.matches();
+    }
+
+    private static Date messageDate(Date date, int hourOfDay, int minute, int second) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
+        cal.set(Calendar.MINUTE, minute);
+        cal.set(Calendar.SECOND, second);
+        return cal.getTime();
+    }
+
+    public static void plugService(Field field, BaseCmd cmd) {
+
+        Class<?> fc = field.getType();
+        Object instance = null;
+
+        if (instance == null) {
+            throw new CloudRuntimeException("Unable to plug service " + fc.getSimpleName() + " in command " + cmd.getClass().getSimpleName());
+        }
+
+        try {
+            field.setAccessible(true);
+            field.set(cmd, instance);
+        } catch (IllegalArgumentException e) {
+            s_logger.error("IllegalArgumentException at plugService for command " + cmd.getCommandName() + ", field " + field.getName());
+            throw new CloudRuntimeException("Internal error at plugService for command " + cmd.getCommandName() + " [Illegal argumet at field " + field.getName() + "]");
+        } catch (IllegalAccessException e) {
+            s_logger.error("Error at plugService for command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
+            throw new CloudRuntimeException("Internal error at plugService for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
+        }
+    }
 }


[22/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fix camelcasing inconsistency causing an assertion error.

java.lang.AssertionError: Searching for a field that's not there: serviceName
	at com.cloud.utils.db.SearchBase.set(SearchBase.java:219)
	at com.cloud.utils.db.SearchBase$Interceptor.intercept(SearchBase.java:475)
	at com.cloud.network.dao.MonitoringServiceVO$$EnhancerByCGLIB$$84195222.getServiceName(<generated>)
	at com.cloud.network.dao.MonitoringServiceDaoImpl.<init>(MonitoringServiceDaoImpl.java:41)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8a9d9798
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8a9d9798
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8a9d9798

Branch: refs/heads/rbac
Commit: 8a9d9798d98e5bb1a212f1686ad8f335744d4b20
Parents: 6523c06
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 14:55:02 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 17:46:33 2014 +0100

----------------------------------------------------------------------
 .../com/cloud/network/MonitoringService.java    |  2 +-
 .../network/dao/MonitoringServiceDaoImpl.java   |  4 +--
 .../cloud/network/dao/MonitoringServiceVO.java  | 28 +++++++++-----------
 3 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8a9d9798/api/src/com/cloud/network/MonitoringService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/MonitoringService.java b/api/src/com/cloud/network/MonitoringService.java
index 63f2ec1..b33e8ff 100644
--- a/api/src/com/cloud/network/MonitoringService.java
+++ b/api/src/com/cloud/network/MonitoringService.java
@@ -39,7 +39,7 @@ public interface MonitoringService extends ControlledEntity, Identity, InternalI
 
     String getServiceName();
 
-    String getPidFile();
+    String getServicePidFile();
 
     String getServicePath();
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8a9d9798/engine/schema/src/com/cloud/network/dao/MonitoringServiceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/MonitoringServiceDaoImpl.java b/engine/schema/src/com/cloud/network/dao/MonitoringServiceDaoImpl.java
index c2292a2..fffb42b 100644
--- a/engine/schema/src/com/cloud/network/dao/MonitoringServiceDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/MonitoringServiceDaoImpl.java
@@ -37,10 +37,10 @@ public class MonitoringServiceDaoImpl extends GenericDaoBase<MonitoringServiceVO
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultService(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("processname", AllFieldsSearch.entity().getProcessname(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("processname", AllFieldsSearch.entity().getProcessName(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("servicename", AllFieldsSearch.entity().getServiceName(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("servicepath", AllFieldsSearch.entity().getServicePath(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("servicePidFile", AllFieldsSearch.entity().getPidFile(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("servicePidFile", AllFieldsSearch.entity().getServicePidFile(), SearchCriteria.Op.EQ);
 
         AllFieldsSearch.done();
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8a9d9798/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java b/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
index 1d7ef14..f9967ec 100644
--- a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
+++ b/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
@@ -31,14 +31,13 @@ import com.cloud.network.MonitoringService;
 @Table(name = "monitoring_services")
 public class MonitoringServiceVO implements MonitoringService {
 
-    public MonitoringServiceVO(String service, String processname, String serviceName, String servicePath, String pidFile, boolean defaultService) {
+    public MonitoringServiceVO(String service, String processName, String serviceName, String servicePath, String servicePidFile, boolean defaultService) {
         this.service = service;
-        this.processname = processname;
-        this.servicename = serviceName;
+        this.processName = processName;
+        this.serviceName = serviceName;
         this.servicePath = servicePath;
-        this.servicePidFile = pidFile;
+        this.servicePidFile = servicePidFile;
         this.defaultService = defaultService;
-
     }
 
     protected MonitoringServiceVO() {
@@ -53,10 +52,10 @@ public class MonitoringServiceVO implements MonitoringService {
     String service;
 
     @Column(name = "process_name", updatable = false)
-    String processname;
+    String processName;
 
     @Column(name = "service_name", updatable = false)
-    String servicename;
+    String serviceName;
 
     @Column(name = "service_path", updatable = false)
     private String servicePath;
@@ -77,23 +76,22 @@ public class MonitoringServiceVO implements MonitoringService {
 
     @Override
     public String getService() {
-        return this.service;
+        return service;
     }
 
     @Override
     public String getServiceName() {
-        return this.servicename;  //To change body of implemented methods use File | Settings | File Templates.
+        return serviceName;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
     @Override
-    public String getPidFile() {
-        return this.servicePidFile;
-
+    public String getServicePidFile() {
+        return servicePidFile;
     }
 
     @Override
     public String getServicePath() {
-        return this.servicePidFile;
+        return servicePidFile;
     }
 
     @Override
@@ -115,7 +113,7 @@ public class MonitoringServiceVO implements MonitoringService {
         return defaultService;
     }
 
-    public String getProcessname() {
-        return processname;
+    public String getProcessName() {
+        return processName;
     }
 }


[26/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
External UUID control support for NetworkACLList/LoadBalancer/ApplicationLoadBalancer


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9641e1db
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9641e1db
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9641e1db

Branch: refs/heads/rbac
Commit: 9641e1dbeeb7c50f7759c563d35b77dd4537fd34
Parents: 3cfa5fb
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Feb 4 22:29:58 2014 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Feb 5 10:36:21 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java         |  1 +
 .../cloud/network/vpc/NetworkACLService.java    |  2 +
 .../UpdateApplicationLoadBalancerCmd.java       | 95 ++++++++++++++++++++
 .../loadbalancer/UpdateLoadBalancerRuleCmd.java | 13 ++-
 .../user/network/UpdateNetworkACLListCmd.java   | 91 +++++++++++++++++++
 .../lb/ApplicationLoadBalancerService.java      |  2 +
 client/tomcatconf/commands.properties.in        |  2 +
 .../src/com/cloud/network/vpc/NetworkACLVO.java |  3 +
 .../lb/LoadBalancingRulesManagerImpl.java       |  5 ++
 .../network/vpc/NetworkACLServiceImpl.java      | 18 ++++
 .../com/cloud/server/ManagementServerImpl.java  |  4 +
 .../lb/ApplicationLoadBalancerManagerImpl.java  | 23 ++++-
 12 files changed, 253 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index fdbc21f..51f8f1b 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -365,6 +365,7 @@ public class EventTypes {
     public static final String EVENT_NETWORK_ACL_CREATE = "NETWORK.ACL.CREATE";
     public static final String EVENT_NETWORK_ACL_DELETE = "NETWORK.ACL.DELETE";
     public static final String EVENT_NETWORK_ACL_REPLACE = "NETWORK.ACL.REPLACE";
+    public static final String EVENT_NETWORK_ACL_UPDATE = "NETWORK.ACL.UPDATE";
     public static final String EVENT_NETWORK_ACL_ITEM_CREATE = "NETWORK.ACL.ITEM.CREATE";
     public static final String EVENT_NETWORK_ACL_ITEM_UPDATE = "NETWORK.ACL.ITEM.UPDATE";
     public static final String EVENT_NETWORK_ACL_ITEM_DELETE = "NETWORK.ACL.ITEM.DELETE";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/com/cloud/network/vpc/NetworkACLService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpc/NetworkACLService.java b/api/src/com/cloud/network/vpc/NetworkACLService.java
index dff718d..29ae4ea 100644
--- a/api/src/com/cloud/network/vpc/NetworkACLService.java
+++ b/api/src/com/cloud/network/vpc/NetworkACLService.java
@@ -130,4 +130,6 @@ public interface NetworkACLService {
      */
     boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException;
 
+    NetworkACL updateNetworkACL(Long id, String customId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java
new file mode 100644
index 0000000..5f89692
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.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.command.user.loadbalancer;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+
+@APICommand(name = "updateLoadBalancer", description = "Updates a Load Balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0")
+public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateApplicationLoadBalancerCmd.class.getName());
+
+    private static final String s_name = "updateloadbalancerresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Load Balancer")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        ApplicationLoadBalancerRule lb = _entityMgr.findById(ApplicationLoadBalancerRule.class, getId());
+        if (lb != null) {
+            return lb.getAccountId();
+        } else {
+            throw new InvalidParameterValueException("Can't find load balancer by id specified");
+        }
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_LOAD_BALANCER_UPDATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "updating load balancer: " + getId();
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public void execute() {
+        CallContext.current().setEventDetails("Load balancer Id: " + getId());
+        ApplicationLoadBalancerRule rule = _appLbService.deleteApplicationLoadBalancer(getId(), this.getCustomId());
+        ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getId()));
+        setResponseObject(lbResponse);
+        lbResponse.setResponseName(getCommandName());
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), ApplicationLoadBalancerRule.class);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
index d68167d..f408756 100644
--- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java
@@ -16,17 +16,17 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.loadbalancer;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.FirewallRuleResponse;
 import org.apache.cloudstack.api.response.LoadBalancerResponse;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
@@ -34,7 +34,7 @@ import com.cloud.network.rules.LoadBalancer;
 import com.cloud.user.Account;
 
 @APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class)
-public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
+public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName());
     private static final String s_name = "updateloadbalancerruleresponse";
 
@@ -132,4 +132,11 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
         }
         return lb.getNetworkId();
     }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), LoadBalancer.class);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
new file mode 100644
index 0000000..333090c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.network;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.NetworkACLResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.vpc.NetworkACL;
+import com.cloud.user.Account;
+
+@APICommand(name = "updateNetworkACLList", description = "Updates Network ACL list", responseObject = SuccessResponse.class, since = "4.4")
+public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName());
+    private static final String s_name = "updatenetworkacllistresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = NetworkACLResponse.class, required = true, description = "the ID of the network ACL")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_NETWORK_ACL_UPDATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return ("Updating network acl list id=" + id);
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Account caller = CallContext.current().getCallingAccount();
+        return caller.getAccountId();
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException {
+        NetworkACL acl = _networkACLService.updateNetworkACL(id, this.getCustomId());
+        NetworkACLResponse aclResponse = _responseGenerator.createNetworkACLResponse(acl);
+        setResponseObject(aclResponse);
+        aclResponse.setResponseName(getCommandName());
+    }
+
+    @Override
+    public void checkUuid() {
+        if (this.getCustomId() != null) {
+            _uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java b/api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java
index 4908918..02bc2fd 100644
--- a/api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java
+++ b/api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java
@@ -39,4 +39,6 @@ public interface ApplicationLoadBalancerService {
 
     ApplicationLoadBalancerRule getApplicationLoadBalancer(long ruleId);
 
+    ApplicationLoadBalancerRule deleteApplicationLoadBalancer(Long id, String customId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 27ed6cf..2992eea 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -471,6 +471,7 @@ createNetworkACLList=15
 deleteNetworkACLList=15
 replaceNetworkACLList=15
 listNetworkACLLists=15
+updateNetworkACLList=15
 
 
 #### Static route commands
@@ -653,6 +654,7 @@ removedeleteUcsManager=1
 createLoadBalancer=15
 listLoadBalancers=15
 deleteLoadBalancer=15
+updateLoadBalancer=15
 
 #Internal Load Balancer Element commands
 configureInternalLoadBalancerElement=7

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java b/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java
index 2f813c8..a0b77c7 100644
--- a/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java
+++ b/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java
@@ -82,4 +82,7 @@ public class NetworkACLVO implements NetworkACL {
         return name;
     }
 
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index cdd3435..ba54191 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -1888,6 +1888,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
         String algorithm = cmd.getAlgorithm();
         LoadBalancerVO lb = _lbDao.findById(lbRuleId);
         LoadBalancerVO lbBackup = _lbDao.findById(lbRuleId);
+        String customId = cmd.getCustomId();
 
         if (lb == null) {
             throw new InvalidParameterValueException("Unable to find lb rule by id=" + lbRuleId);
@@ -1908,6 +1909,10 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
             lb.setAlgorithm(algorithm);
         }
 
+        if (customId != null) {
+            lb.setUuid(customId);
+        }
+
         boolean success = _lbDao.update(lbRuleId, lb);
 
         // If algorithm is changed, have to reapply the lb config

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
index a9d2b1d..ec43883 100644
--- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@ -33,6 +33,8 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.Network;
@@ -637,4 +639,20 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
         return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID);
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE, eventDescription = "updating network acl", async = true)
+    public NetworkACL updateNetworkACL(Long id, String customId) {
+        NetworkACLVO acl = _networkACLDao.findById(id);
+        Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
+        Account caller = CallContext.current().getCallingAccount();
+        _accountMgr.checkAccess(caller, null, true, vpc);
+
+        if (customId != null) {
+            acl.setUuid(customId);
+        }
+
+        _networkACLDao.update(id, acl);
+        return _networkACLDao.findById(id);
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/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 ec40411..ad4e760 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -294,6 +294,7 @@ import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRules
 import org.apache.cloudstack.api.command.user.loadbalancer.ListSslCertsCmd;
 import org.apache.cloudstack.api.command.user.loadbalancer.RemoveCertFromLoadBalancerCmd;
 import org.apache.cloudstack.api.command.user.loadbalancer.RemoveFromLoadBalancerRuleCmd;
+import org.apache.cloudstack.api.command.user.loadbalancer.UpdateApplicationLoadBalancerCmd;
 import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
 import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
 import org.apache.cloudstack.api.command.user.nat.CreateIpForwardingRuleCmd;
@@ -314,6 +315,7 @@ import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
 import org.apache.cloudstack.api.command.user.network.ReplaceNetworkACLListCmd;
 import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
 import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLItemCmd;
+import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
 import org.apache.cloudstack.api.command.user.network.UpdateNetworkCmd;
 import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
 import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
@@ -2853,6 +2855,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(GetVMUserDataCmd.class);
         cmdList.add(UpdateEgressFirewallRuleCmd.class);
         cmdList.add(UpdateFirewallRuleCmd.class);
+        cmdList.add(UpdateNetworkACLListCmd.class);
+        cmdList.add(UpdateApplicationLoadBalancerCmd.class);
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9641e1db/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
index 9c93b46..61ad8f9 100644
--- a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
+++ b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
@@ -24,15 +24,14 @@ import java.util.Map;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
 import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
@@ -525,4 +524,22 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
             s_logger.debug("No network rule conflicts detected for " + newLbRule + " against " + (lbRules.size() - 1) + " existing rules");
         }
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_UPDATE, eventDescription = "updating load balancer", async = true)
+    public ApplicationLoadBalancerRule deleteApplicationLoadBalancer(Long id, String customId) {
+        Account caller = CallContext.current().getCallingAccount();
+        ApplicationLoadBalancerRuleVO rule = _lbDao.findById(id);
+
+        if (rule == null) {
+            throw new InvalidParameterValueException("Unable to find load balancer " + id);
+        }
+        _accountMgr.checkAccess(caller, null, true, rule);
+        if (customId != null) {
+            rule.setUuid(customId);
+        }
+        _lbDao.update(id, rule);
+
+        return _lbDao.findById(id);
+    }
 }


[13/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
stratosphere-ssp plugin: Fix HttpClient4 connection leak

Replaced HttpClient#execute(HttpUriRequest) with
HttpClient#execute(HttpUriRequest,ResponseHandler<T>).
The former requires extra EntityUtils#consume(HttpEntity).


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0d222b14
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0d222b14
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0d222b14

Branch: refs/heads/rbac
Commit: 0d222b14a156f9ec60c137b83ef3cc7e78c90133
Parents: 54f32a8
Author: Hiroaki KAWAI <ka...@stratosphere.co.jp>
Authored: Wed Feb 5 16:20:10 2014 +0900
Committer: Hiroaki KAWAI <ka...@stratosphere.co.jp>
Committed: Wed Feb 5 16:23:32 2014 +0900

----------------------------------------------------------------------
 .../cloudstack/network/element/SspClient.java   | 110 ++++++-------------
 .../network/element/SspClientTest.java          |  20 +---
 2 files changed, 36 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0d222b14/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspClient.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspClient.java b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspClient.java
index 4d0be2d..30630a3 100644
--- a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspClient.java
+++ b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspClient.java
@@ -17,15 +17,15 @@
 package org.apache.cloudstack.network.element;
 
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
 
-import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.HttpResponseException;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpDelete;
 import org.apache.http.client.methods.HttpPost;
@@ -35,6 +35,7 @@ import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.params.CookiePolicy;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.conn.PoolingClientConnectionManager;
 import org.apache.http.message.BasicNameValuePair;
@@ -42,8 +43,6 @@ import org.apache.http.params.CoreConnectionPNames;
 import org.apache.log4j.Logger;
 
 import com.google.gson.Gson;
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
 import com.google.gson.annotations.SerializedName;
 
 /**
@@ -74,7 +73,7 @@ public class SspClient {
         return s_client;
     }
 
-    private HttpResponse innerExecuteMethod(HttpRequestBase req, String path) {
+    private String executeMethod(HttpRequestBase req, String path) {
         try {
             URI base = new URI(apiUrl);
             req.setURI(new URI(base.getScheme(), base.getUserInfo(), base.getHost(),
@@ -83,23 +82,26 @@ public class SspClient {
             s_logger.error("invalid API URL " + apiUrl + " path " + path, e);
             return null;
         }
-        HttpResponse res = null;
         try {
-            res = getHttpClient().execute(req);
-            s_logger.info("ssp api call:" + req + " status=" + res.getStatusLine());
+            String content = null;
+            try {
+                content = getHttpClient().execute(req, new BasicResponseHandler());
+                s_logger.info("ssp api call: " + req);
+            } catch (HttpResponseException e) {
+                s_logger.info("ssp api call failed: " + req, e);
+                if (e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED && login()) {
+                    req.reset();
+                    content = getHttpClient().execute(req, new BasicResponseHandler());
+                    s_logger.info("ssp api retry call: " + req);
+                }
+            }
+            return content;
+        } catch (ClientProtocolException e) { // includes HttpResponseException
+            s_logger.error("ssp api call failed: " + req, e);
         } catch (IOException e) {
             s_logger.error("ssp api call failed: " + req, e);
         }
-        return res;
-    }
-
-    private HttpResponse executeMethod(HttpRequestBase req, String path) {
-        HttpResponse res = innerExecuteMethod(req, path);
-        if (res.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && login()) {
-            req.reset();
-            res = innerExecuteMethod(req, path);
-        }
-        return res;
+        return null;
     }
 
     public boolean login() {
@@ -112,9 +114,7 @@ public class SspClient {
             s_logger.error("invalid username or password", e);
             return false;
         }
-
-        HttpResponse res = this.innerExecuteMethod(method, "/ws.v1/login");
-        if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+        if (executeMethod(method, "/ws.v1/login") != null) {
             return true;
         }
         return false;
@@ -134,29 +134,14 @@ public class SspClient {
 
         HttpPost method = new HttpPost();
         method.setEntity(new StringEntity(new Gson().toJson(req), ContentType.APPLICATION_JSON));
-        HttpResponse res = executeMethod(method, "/ssp.v1/tenant-networks");
-        if (res == null || res.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
-            return null;
-        }
-        try {
-            return new Gson().fromJson(new InputStreamReader(res.getEntity().getContent(), "UTF-8"),
-                    TenantNetwork.class);
-        } catch (JsonSyntaxException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (JsonIOException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IllegalStateException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IOException e) {
-            s_logger.error("reading response body failed", e);
-        }
-        return null;
+        return new Gson().fromJson(
+                executeMethod(method, "/ssp.v1/tenant-networks"),
+                TenantNetwork.class);
     }
 
     public boolean deleteTenantNetwork(String tenantNetworkUuid) {
         HttpDelete method = new HttpDelete();
-        HttpResponse res = executeMethod(method, "/ssp.v1/tenant-networks/" + tenantNetworkUuid);
-        if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
+        if (executeMethod(method, "/ssp.v1/tenant-networks/" + tenantNetworkUuid) != null) {
             return true;
         }
         return false;
@@ -182,31 +167,14 @@ public class SspClient {
 
         HttpPost method = new HttpPost();
         method.setEntity(new StringEntity(new Gson().toJson(req), ContentType.APPLICATION_JSON));
-        HttpResponse res = executeMethod(method, "/ssp.v1/tenant-ports");
-
-        if (res == null || res.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
-            return null;
-        }
-        try {
-            return new Gson().fromJson(new InputStreamReader(res.getEntity().getContent(), "UTF-8"),
-                    TenantPort.class);
-        } catch (JsonSyntaxException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (JsonIOException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IllegalStateException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IOException e) {
-            s_logger.error("reading response body failed", e);
-        }
-        return null;
+        return new Gson().fromJson(
+                executeMethod(method, "/ssp.v1/tenant-ports"),
+                TenantPort.class);
     }
 
     public boolean deleteTenantPort(String tenantPortUuid) {
         HttpDelete method = new HttpDelete();
-        HttpResponse res = executeMethod(method, "/ssp.v1/tenant-ports/" + tenantPortUuid);
-
-        if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
+        if (executeMethod(method, "/ssp.v1/tenant-ports/" + tenantPortUuid) != null) {
             return true;
         }
         return false;
@@ -223,22 +191,8 @@ public class SspClient {
 
         HttpPut method = new HttpPut();
         method.setEntity(new StringEntity(new Gson().toJson(req), ContentType.APPLICATION_JSON));
-        HttpResponse res = executeMethod(method, "/ssp.v1/tenant-ports/" + portUuid);
-        if (res == null || res.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
-            return null;
-        }
-        try {
-            return new Gson().fromJson(new InputStreamReader(res.getEntity().getContent(), "UTF-8"),
-                    TenantPort.class);
-        } catch (JsonSyntaxException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (JsonIOException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IllegalStateException e) {
-            s_logger.error("reading response body failed", e);
-        } catch (IOException e) {
-            s_logger.error("reading response body failed", e);
-        }
-        return null;
+        return new Gson().fromJson(
+                executeMethod(method, "/ssp.v1/tenant-ports/" + portUuid),
+                TenantPort.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0d222b14/plugins/network-elements/stratosphere-ssp/test/org/apache/cloudstack/network/element/SspClientTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/stratosphere-ssp/test/org/apache/cloudstack/network/element/SspClientTest.java b/plugins/network-elements/stratosphere-ssp/test/org/apache/cloudstack/network/element/SspClientTest.java
index 627cc87..a6b723c 100644
--- a/plugins/network-elements/stratosphere-ssp/test/org/apache/cloudstack/network/element/SspClientTest.java
+++ b/plugins/network-elements/stratosphere-ssp/test/org/apache/cloudstack/network/element/SspClientTest.java
@@ -23,15 +23,11 @@ import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-
-import java.io.ByteArrayInputStream;
 import java.util.UUID;
 
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.BasicResponseHandler;
 import org.junit.Test;
 
 public class SspClientTest {
@@ -46,10 +42,8 @@ public class SspClientTest {
         SspClient sspClient = spy(new SspClient(apiUrl, username, password));
 
         HttpClient client = mock(HttpClient.class);
-        HttpResponse res = mock(HttpResponse.class, RETURNS_DEEP_STUBS);
         doReturn(client).when(sspClient).getHttpClient();
-        when(client.execute(any(HttpUriRequest.class))).thenReturn(res);
-        when(res.getStatusLine().getStatusCode()).thenReturn(HttpStatus.SC_OK);
+        when(client.execute(any(HttpUriRequest.class), any(BasicResponseHandler.class))).thenReturn("");
 
         assertTrue(sspClient.login());
         assertTrue(sspClient.login());
@@ -63,14 +57,10 @@ public class SspClientTest {
         SspClient sspClient = spy(new SspClient(apiUrl, username, password));
 
         HttpClient client = mock(HttpClient.class);
-        HttpResponse res = mock(HttpResponse.class, RETURNS_DEEP_STUBS);
         doReturn(client).when(sspClient).getHttpClient();
-        when(client.execute(any(HttpUriRequest.class))).thenReturn(res);
-        when(res.getStatusLine().getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
         String body = "{\"uuid\":\"" + tenant_net_uuid + "\",\"name\":\"" + networkName
                 + "\",\"tenant_uuid\":\"" + uuid + "\"}";
-        when(res.getEntity().getContent()).thenReturn(
-                new ByteArrayInputStream(body.getBytes("UTF-8")));
+        when(client.execute(any(HttpUriRequest.class), any(BasicResponseHandler.class))).thenReturn(body);
 
         SspClient.TenantNetwork tnet = sspClient.createTenantNetwork(uuid, networkName);
         assertEquals(tnet.name, networkName);
@@ -84,10 +74,8 @@ public class SspClientTest {
         SspClient sspClient = spy(new SspClient(apiUrl, username, password));
 
         HttpClient client = mock(HttpClient.class);
-        HttpResponse res = mock(HttpResponse.class, RETURNS_DEEP_STUBS);
         doReturn(client).when(sspClient).getHttpClient();
-        when(client.execute(any(HttpUriRequest.class))).thenReturn(res);
-        when(res.getStatusLine().getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
+        when(client.execute(any(HttpUriRequest.class), any(BasicResponseHandler.class))).thenReturn("");
 
         sspClient.deleteTenantNetwork(tenant_net_uuid);
     }


[50/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Merge branch 'master' into rbac.



Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3b58a45e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3b58a45e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3b58a45e

Branch: refs/heads/rbac
Commit: 3b58a45e049c3341c7b54f9d09bff5f7088c9425
Parents: c440d90 3384633
Author: Min Chen <mi...@citrix.com>
Authored: Fri Feb 7 13:43:36 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Fri Feb 7 13:43:36 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java         |    6 +
 .../com/cloud/network/MonitoringService.java    |    2 +-
 api/src/com/cloud/network/NetworkService.java   |    4 +-
 .../cloud/network/firewall/FirewallService.java |    2 +
 .../com/cloud/network/rules/RulesService.java   |    2 +
 .../cloud/network/vpc/NetworkACLService.java    |    5 +-
 api/src/com/cloud/network/vpc/VpcService.java   |    3 +-
 .../network/vpn/RemoteAccessVpnService.java     |    5 +
 .../cloud/network/vpn/Site2SiteVpnService.java  |    4 +
 api/src/com/cloud/storage/Storage.java          |    5 +-
 .../cloudstack/api/BaseAsyncCustomIdCmd.java    |    7 +-
 api/src/org/apache/cloudstack/api/BaseCmd.java  |    6 +-
 .../apache/cloudstack/api/BaseCustomIdCmd.java  |    7 +-
 .../admin/network/UpdateNetworkCmdByAdmin.java  |    2 +-
 .../command/admin/vpc/UpdateVPCCmdByAdmin.java  |    2 +-
 .../command/user/address/UpdateIPAddrCmd.java   |  124 +
 .../autoscale/UpdateAutoScaleVmGroupCmd.java    |   13 +-
 .../autoscale/UpdateAutoScaleVmProfileCmd.java  |   13 +-
 .../firewall/UpdateEgressFirewallRuleCmd.java   |  113 +
 .../user/firewall/UpdateFirewallRuleCmd.java    |  114 +
 .../firewall/UpdatePortForwardingRuleCmd.java   |   29 +-
 .../UpdateApplicationLoadBalancerCmd.java       |   96 +
 .../loadbalancer/UpdateLoadBalancerRuleCmd.java |   14 +-
 .../user/network/UpdateNetworkACLItemCmd.java   |   16 +-
 .../user/network/UpdateNetworkACLListCmd.java   |   91 +
 .../command/user/network/UpdateNetworkCmd.java  |   14 +-
 .../api/command/user/vm/UpdateVMCmd.java        |    8 +
 .../command/user/volume/UpdateVolumeCmd.java    |    9 +
 .../api/command/user/vpc/UpdateVPCCmd.java      |   14 +-
 .../user/vpn/UpdateRemoteAccessVpnCmd.java      |  102 +
 .../user/vpn/UpdateVpnConnectionCmd.java        |   90 +
 .../command/user/vpn/UpdateVpnGatewayCmd.java   |   89 +
 .../Site2SiteVpnConnectionResponse.java         |    5 +-
 .../lb/ApplicationLoadBalancerService.java      |    2 +
 client/pom.xml                                  |   25 +-
 client/tomcatconf/commands.properties.in        |    9 +
 .../api/storage/StorageCacheManager.java        |    2 +
 .../cloud/network/vpc/NetworkACLManager.java    |    3 +-
 .../com/cloud/agent/manager/AgentAttache.java   |    2 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java |    2 +-
 .../orchestration/NetworkOrchestrator.java      |   19 +-
 .../cloud/network/as/AutoScaleVmGroupVO.java    |    4 +
 .../cloud/network/as/AutoScaleVmProfileVO.java  |    9 +-
 .../network/dao/MonitoringServiceDaoImpl.java   |    4 +-
 .../cloud/network/dao/MonitoringServiceVO.java  |   22 +-
 .../cloud/network/dao/RemoteAccessVpnVO.java    |    4 +
 .../network/dao/Site2SiteVpnConnectionVO.java   |    4 +
 .../network/dao/Site2SiteVpnGatewayVO.java      |    4 +
 .../com/cloud/network/vpc/NetworkACLItemVO.java |    4 +
 .../src/com/cloud/network/vpc/NetworkACLVO.java |    3 +
 .../schema/src/com/cloud/network/vpc/VpcVO.java |   13 +-
 .../resourcedetail/ResourceDetailsDaoBase.java  |    5 +-
 .../storage/datastore/db/ImageStoreVO.java      |   10 +-
 .../storage/datastore/db/StoragePoolVO.java     |   15 +-
 .../cache/allocator/StorageCacheAllocator.java  |    3 +
 .../allocator/StorageCacheRandomAllocator.java  |   38 +
 .../cache/manager/StorageCacheManagerImpl.java  |   13 +
 .../motion/AncientDataMotionStrategy.java       |    4 +-
 .../storage/test/ChildTestConfiguration.java    |    6 -
 .../storage/snapshot/SnapshotObject.java        |    3 +
 .../storage/snapshot/SnapshotServiceImpl.java   |    8 +-
 .../snapshot/XenserverSnapshotStrategy.java     |    5 +
 .../endpoint/DefaultEndPointSelector.java       |    3 +-
 .../storage/image/format/ImageFormatHelper.java |    2 +-
 .../datastore/PrimaryDataStoreHelper.java       |    2 +-
 .../storage/datastore/PrimaryDataStoreImpl.java |    5 +-
 .../HypervResource/CloudStackTypes.cs           |    8 +-
 .../HypervResource/HypervResourceController.cs  |    8 +-
 .../ServerResource/HypervResource/WmiCallsV2.cs |    8 +-
 .../kvm/resource/LibvirtComputingResource.java  |   56 +-
 .../kvm/resource/LibvirtDomainXMLParser.java    |    4 +-
 .../hypervisor/kvm/resource/LibvirtVMDef.java   |   16 +
 .../kvm/storage/KVMStorageProcessor.java        |    2 +
 .../kvm/storage/LibvirtStorageAdaptor.java      |    6 +
 .../resource/LibvirtDomainXMLParserTest.java    |  194 ++
 .../com/cloud/hypervisor/guru/VMwareGuru.java   |   36 +-
 .../vmware/manager/VmwareManagerImpl.java       |   94 +-
 .../resource/VmwareStorageProcessor.java        |    6 +
 .../VmwareStorageSubsystemCommandHandler.java   |   51 +-
 .../vmware/VmwareDatacenterApiUnitTest.java     |    6 -
 .../xen/resource/CitrixResourceBase.java        |    7 +-
 .../contrail/management/ContrailGuru.java       |   42 +-
 .../management/ContrailManagerImpl.java         |    6 +-
 .../IntegrationTestConfiguration.java           |    6 -
 plugins/network-elements/netscaler/pom.xml      |    8 +-
 .../network/resource/NetscalerResource.java     |  149 +-
 .../cloudstack/network/element/SspClient.java   |  110 +-
 .../network/element/SspClientTest.java          |   20 +-
 plugins/pom.xml                                 |   12 +-
 ...CloudStackPrimaryDataStoreLifeCycleImpl.java |    8 +-
 pom.xml                                         |    6 +-
 .../spring-server-core-managers-context.xml     |    6 -
 server/src/com/cloud/api/ApiDispatcher.java     |   12 +-
 .../com/cloud/api/query/vo/UserVmJoinVO.java    |   23 +-
 .../configuration/ConfigurationManagerImpl.java |   41 +-
 .../com/cloud/consoleproxy/AgentHookBase.java   |    5 +-
 .../ConsoleProxyBalanceAllocator.java           |    3 -
 .../consoleproxy/StaticConsoleProxyManager.java |   18 -
 .../src/com/cloud/dc/DedicatedResourceVO.java   |   10 +-
 .../com/cloud/network/IpAddressManagerImpl.java |   36 +-
 .../src/com/cloud/network/NetworkModelImpl.java |    7 +-
 .../com/cloud/network/NetworkServiceImpl.java   |   29 +-
 .../cloud/network/as/AutoScaleManagerImpl.java  |   20 +-
 .../network/firewall/FirewallManagerImpl.java   |   31 +-
 .../cloud/network/guru/ControlNetworkGuru.java  |    4 +-
 .../lb/LoadBalancingRulesManagerImpl.java       |   15 +-
 .../VirtualNetworkApplianceManagerImpl.java     | 1587 ++++++------
 .../cloud/network/rules/RulesManagerImpl.java   |   20 +-
 .../network/vpc/NetworkACLManagerImpl.java      |    9 +-
 .../network/vpc/NetworkACLServiceImpl.java      |   22 +-
 .../com/cloud/network/vpc/VpcManagerImpl.java   |   15 +-
 .../network/vpn/RemoteAccessVpnManagerImpl.java |   26 +-
 .../network/vpn/Site2SiteVpnManagerImpl.java    |   42 +-
 .../com/cloud/resource/ResourceManagerImpl.java |   66 +-
 .../PremiumSecondaryStorageManagerImpl.java     |  185 --
 .../cloud/server/ConfigurationServerImpl.java   |  413 +--
 .../com/cloud/server/ManagementServerImpl.java  |   51 +-
 .../com/cloud/storage/VolumeApiServiceImpl.java |  188 +-
 .../storage/download/DownloadMonitorImpl.java   |   29 +-
 .../secondary/SecondaryStorageListener.java     |    5 +-
 .../secondary/SecondaryStorageManagerImpl.java  | 1389 ----------
 .../storage/snapshot/SnapshotManagerImpl.java   |   66 +-
 .../cloud/storage/upload/UploadMonitorImpl.java |   27 +-
 .../com/cloud/template/TemplateManagerImpl.java |  135 +-
 .../src/com/cloud/uuididentity/UUIDManager.java |   37 -
 .../com/cloud/uuididentity/UUIDManagerImpl.java |    1 +
 server/src/com/cloud/vm/UserVmManagerImpl.java  |   15 +-
 .../lb/ApplicationLoadBalancerManagerImpl.java  |   23 +-
 .../cloudstack/network/lb/CertServiceImpl.java  |   14 +-
 .../cloud/network/MockFirewallManagerImpl.java  |    6 +
 .../com/cloud/vpc/MockNetworkManagerImpl.java   |   13 +-
 .../cloud/vpc/MockSite2SiteVpnManagerImpl.java  |   15 +-
 .../com/cloud/vpc/NetworkACLManagerTest.java    |    9 +-
 .../networkoffering/ChildTestConfiguration.java |    6 -
 .../consoleproxy/ConsoleProxyRdpClient.java     |  147 +-
 .../ConsoleProxyThumbnailHandler.java           |    1 +
 services/secondary-storage/controller/pom.xml   |   50 +
 ...econdary-storage-controller-core-context.xml |   33 +
 .../PremiumSecondaryStorageManagerImpl.java     |  186 ++
 .../SecondaryStorageManagerImpl.java            | 1388 ++++++++++
 services/secondary-storage/pom.xml              |   85 +-
 .../module.properties                           |   18 -
 ...ing-secondary-storage-discoverer-context.xml |   36 -
 services/secondary-storage/server/pom.xml       |  105 +
 .../module.properties                           |   18 +
 ...ing-secondary-storage-discoverer-context.xml |   36 +
 .../LocalNfsSecondaryStorageResource.java       |   95 +
 .../resource/LocalSecondaryStorageResource.java |  240 ++
 .../resource/NfsSecondaryStorageResource.java   | 2430 ++++++++++++++++++
 .../resource/SecondaryStorageDiscoverer.java    |  312 +++
 .../resource/SecondaryStorageResource.java      |   29 +
 .../SecondaryStorageResourceHandler.java        |   24 +
 .../storage/template/DownloadManager.java       |  108 +
 .../storage/template/DownloadManagerImpl.java   | 1080 ++++++++
 .../storage/template/UploadManager.java         |   82 +
 .../storage/template/UploadManagerImpl.java     |  550 ++++
 .../LocalNfsSecondaryStorageResourceTest.java   |  143 ++
 .../NfsSecondaryStorageResourceTest.java        |  110 +
 .../LocalNfsSecondaryStorageResource.java       |   95 -
 .../resource/LocalSecondaryStorageResource.java |  240 --
 .../resource/NfsSecondaryStorageResource.java   | 2430 ------------------
 .../resource/SecondaryStorageDiscoverer.java    |  312 ---
 .../resource/SecondaryStorageResource.java      |   29 -
 .../SecondaryStorageResourceHandler.java        |   24 -
 .../storage/template/DownloadManager.java       |  108 -
 .../storage/template/DownloadManagerImpl.java   | 1080 --------
 .../storage/template/UploadManager.java         |   82 -
 .../storage/template/UploadManagerImpl.java     |  550 ----
 .../LocalNfsSecondaryStorageResourceTest.java   |  143 --
 .../NfsSecondaryStorageResourceTest.java        |  110 -
 setup/db/create-schema.sql                      |    2 +-
 .../patches/debian/config/etc/dnsmasq.conf.tmpl |    2 +-
 .../patches/debian/config/etc/vpcdnsmasq.conf   |    2 +-
 .../definitions/systemvm64template/base.sh      |    6 +-
 .../systemvm64template/definition.rb            |    6 +-
 .../systemvm64template/postinstall.sh           |   14 +-
 .../definitions/systemvmtemplate/base.sh        |    4 +-
 .../definitions/systemvmtemplate/definition.rb  |    6 +-
 .../definitions/systemvmtemplate/postinstall.sh |   10 +-
 ui/scripts/configuration.js                     |   12 +-
 ui/scripts/instances.js                         |    2 +-
 ui/scripts/system.js                            |   33 +-
 ui/scripts/ui/widgets/detailView.js             |    3 +-
 utils/src/com/cloud/utils/UriUtils.java         |   60 +
 utils/src/com/cloud/utils/db/UUIDManager.java   |   37 +
 utils/src/com/cloud/utils/net/Ip.java           |    2 +-
 utils/test/com/cloud/utils/net/IpTest.java      |   43 +
 187 files changed, 10508 insertions(+), 9061 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
index cab88d4,0000000..644a0fa
mode 100644,000000..100644
--- a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
@@@ -1,63 -1,0 +1,63 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +package org.apache.cloudstack.api.command.admin.network;
 +
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.api.APICommand;
 +import org.apache.cloudstack.api.ApiErrorCode;
 +import org.apache.cloudstack.api.ResponseObject.ResponseView;
 +import org.apache.cloudstack.api.ServerApiException;
 +import org.apache.cloudstack.api.command.user.network.UpdateNetworkCmd;
 +import org.apache.cloudstack.api.response.NetworkResponse;
 +import org.apache.cloudstack.context.CallContext;
 +
 +import com.cloud.exception.ConcurrentOperationException;
 +import com.cloud.exception.InsufficientCapacityException;
 +import com.cloud.exception.InvalidParameterValueException;
 +import com.cloud.network.Network;
 +import com.cloud.user.Account;
 +import com.cloud.user.User;
 +
 +@APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full)
 +public class UpdateNetworkCmdByAdmin extends UpdateNetworkCmd {
 +    public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmdByAdmin.class.getName());
 +
 +
 +    @Override
 +    public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
 +        User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
 +        Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
 +        Network network = _networkService.getNetwork(id);
 +        if (network == null) {
 +            throw new InvalidParameterValueException("Couldn't find network by id");
 +        }
 +
 +        Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
-                     callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr(), getDisplayNetwork());
++                callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId());
 +
 +
 +        if (result != null) {
 +            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
 +            response.setResponseName(getCommandName());
 +            setResponseObject(response);
 +        } else {
 +            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
 +        }
 +    }
 +
 +}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
index a0e8021,0000000..372bb75
mode 100644,000000..100644
--- a/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
@@@ -1,47 -1,0 +1,47 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +package org.apache.cloudstack.api.command.admin.vpc;
 +
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.api.APICommand;
 +import org.apache.cloudstack.api.ApiErrorCode;
 +import org.apache.cloudstack.api.ResponseObject.ResponseView;
 +import org.apache.cloudstack.api.ServerApiException;
 +import org.apache.cloudstack.api.command.user.vpc.UpdateVPCCmd;
 +import org.apache.cloudstack.api.response.VpcResponse;
 +
 +import com.cloud.network.vpc.Vpc;
 +
 +@APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Full)
 +public class UpdateVPCCmdByAdmin extends UpdateVPCCmd {
 +    public static final Logger s_logger = Logger.getLogger(UpdateVPCCmdByAdmin.class.getName());
 +
 +    @Override
 +    public void execute(){
-         Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText());
++        Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId());
 +        if (result != null) {
 +            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
 +            response.setResponseName(getCommandName());
 +            setResponseObject(response);
 +        } else {
 +            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
 +        }
 +    }
 +
 +
 +}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
index 0000000,b45bf94..ea55dc4
mode 000000,100644..100644
--- a/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java
@@@ -1,0 -1,122 +1,124 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ package org.apache.cloudstack.api.command.user.address;
+ 
++import org.apache.log4j.Logger;
++
+ import org.apache.cloudstack.api.APICommand;
+ import org.apache.cloudstack.api.ApiConstants;
+ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
+ import org.apache.cloudstack.api.Parameter;
++import org.apache.cloudstack.api.ResponseObject.ResponseView;
+ import org.apache.cloudstack.api.ServerApiException;
+ import org.apache.cloudstack.api.response.AccountResponse;
+ import org.apache.cloudstack.api.response.IPAddressResponse;
 -import org.apache.log4j.Logger;
+ 
+ import com.cloud.event.EventTypes;
+ import com.cloud.exception.ConcurrentOperationException;
+ import com.cloud.exception.InsufficientCapacityException;
+ import com.cloud.exception.InvalidParameterValueException;
+ import com.cloud.exception.NetworkRuleConflictException;
+ import com.cloud.exception.ResourceAllocationException;
+ import com.cloud.exception.ResourceUnavailableException;
+ import com.cloud.network.IpAddress;
+ import com.cloud.user.Account;
+ 
+ @APICommand(name = "updatePublicIpAddress", description = "Updates an ip address", responseObject = IPAddressResponse.class)
+ public class UpdateIPAddrCmd extends BaseAsyncCustomIdCmd {
+     public static final Logger s_logger = Logger.getLogger(UpdateIPAddrCmd.class.getName());
+     private static final String s_name = "updateipaddressresponse";
+ 
+     /////////////////////////////////////////////////////
+     //////////////// API parameters /////////////////////
+     /////////////////////////////////////////////////////
+ 
+     @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IPAddressResponse.class, required = true, description = "the id of the public ip address"
+             + " to update")
+     private Long id;
+     // unexposed parameter needed for events logging
+     @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
+     private Long ownerId;
+ 
+     /////////////////////////////////////////////////////
+     /////////////////// Accessors ///////////////////////
+     /////////////////////////////////////////////////////
+     @Override
+     public String getCommandName() {
+         return s_name;
+     }
+ 
+     public Long getId() {
+         return id;
+     }
+ 
+ 
+     /////////////////////////////////////////////////////
+     /////////////// API Implementation///////////////////
+     /////////////////////////////////////////////////////
+     @Override
+     public String getEventType() {
+         return EventTypes.EVENT_NET_IP_UPDATE;
+     }
+ 
+     @Override
+     public String getEventDescription() {
+         return ("Updating ip address with id=" + id);
+     }
+ 
+     @Override
+     public long getEntityOwnerId() {
+         if (ownerId == null) {
+             IpAddress ip = getIpAddress(id);
+             if (ip == null) {
+                 throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+             }
+             ownerId = ip.getAccountId();
+         }
+ 
+         if (ownerId == null) {
+             return Account.ACCOUNT_ID_SYSTEM;
+         }
+         return ownerId;
+     }
+ 
+     private IpAddress getIpAddress(long id) {
+         IpAddress ip = _entityMgr.findById(IpAddress.class, id);
+ 
+         if (ip == null) {
+             throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+         } else {
+             return ip;
+         }
+     }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), IpAddress.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), IpAddress.class);
+         }
+     }
+ 
+     @Override
+     public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
+             NetworkRuleConflictException {
+ 
 -        IpAddress result = _networkService.updateIP(getId(), this.getCustomId());
 -        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
++        IpAddress result = _networkService.updateIP(getId(), getCustomId());
++        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, result);
+         ipResponse.setResponseName(getCommandName());
+         setResponseObject(ipResponse);
+     }
+ }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java
index 0aba633,628bb8a..7c205f3
--- a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java
@@@ -39,8 -35,8 +39,8 @@@ import com.cloud.event.EventTypes
  import com.cloud.network.as.AutoScaleVmGroup;
  import com.cloud.user.Account;
  
 -@APICommand(name = "updateAutoScaleVmGroup", description = "Updates an existing autoscale vm group.", responseObject = AutoScaleVmGroupResponse.class)
 +@APICommand(name = "updateAutoScaleVmGroup", description = "Updates an existing autoscale vm group.", responseObject = AutoScaleVmGroupResponse.class, entityType = { AclEntityType.AutoScaleVmGroup })
- public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd {
+ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd {
      public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmGroupCmd.class.getName());
  
      private static final String s_name = "updateautoscalevmgroupresponse";
@@@ -95,7 -90,7 +95,7 @@@
          if (result != null) {
              AutoScaleVmGroupResponse response = _responseGenerator.createAutoScaleVmGroupResponse(result);
              response.setResponseName(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale VmGroup");
          }
@@@ -158,4 -153,11 +158,11 @@@
      public ApiCommandJobType getInstanceType() {
          return ApiCommandJobType.AutoScaleVmGroup;
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), AutoScaleVmGroup.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), AutoScaleVmGroup.class);
+         }
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java
index 2d76c51,d6405c1..959b829
--- a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java
@@@ -40,8 -36,8 +40,8 @@@ import com.cloud.event.EventTypes
  import com.cloud.network.as.AutoScaleVmProfile;
  import com.cloud.user.Account;
  
 -@APICommand(name = "updateAutoScaleVmProfile", description = "Updates an existing autoscale vm profile.", responseObject = AutoScaleVmProfileResponse.class)
 +@APICommand(name = "updateAutoScaleVmProfile", description = "Updates an existing autoscale vm profile.", responseObject = AutoScaleVmProfileResponse.class, entityType = { AclEntityType.AutoScaleVmProfile })
- public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd {
+ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
      public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmProfileCmd.class.getName());
  
      private static final String s_name = "updateautoscalevmprofileresponse";
@@@ -91,7 -86,7 +91,7 @@@
          if (result != null) {
              AutoScaleVmProfileResponse response = _responseGenerator.createAutoScaleVmProfileResponse(result);
              response.setResponseName(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale vm profile");
          }
@@@ -150,4 -145,11 +150,11 @@@
      public ApiCommandJobType getInstanceType() {
          return ApiCommandJobType.AutoScaleVmProfile;
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), AutoScaleVmProfile.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), AutoScaleVmProfile.class);
+         }
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
index 6c860fe,a7bb7e3..79d3ce6
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java
@@@ -34,8 -35,8 +37,8 @@@ import com.cloud.user.Account
  
  @APICommand(name = "updatePortForwardingRule",
              responseObject = FirewallRuleResponse.class,
-  description = "Updates a port forwarding rule.  Only the private port and the virtual machine can be updated.", entityType = { AclEntityType.PortForwardingRule })
- public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
 - description = "Updates a port forwarding rule")
++        description = "Updates a port forwarding rule.  Only the private port and the virtual machine can be updated.", entityType = {AclEntityType.PortForwardingRule})
+ public class UpdatePortForwardingRuleCmd extends BaseAsyncCustomIdCmd {
      public static final Logger s_logger = Logger.getLogger(UpdatePortForwardingRuleCmd.class.getName());
      private static final String s_name = "updateportforwardingruleresponse";
  
@@@ -130,7 -131,21 +133,21 @@@
      }
  
      @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), FirewallRule.class);
+         }
+     }
+ 
+     @Override
      public void execute() {
 -        PortForwardingRule rule = _rulesService.updatePortForwardingRule(id, this.getCustomId());
++        PortForwardingRule rule = _rulesService.updatePortForwardingRule(id, getCustomId());
+         FirewallRuleResponse fwResponse = new FirewallRuleResponse();
+         if (rule != null) {
+             fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
+             setResponseObject(fwResponse);
+         }
+         fwResponse.setResponseName(getCommandName());
  //FIXME:        PortForwardingRule result = _mgr.updatePortForwardingRule(this);
  //        if (result != null) {
  //            FirewallRuleResponse response = _responseGenerator.createFirewallRuleResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
index 139f81a,85bea5f..215a1da
--- a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
@@@ -25,8 -20,8 +25,9 @@@ import org.apache.cloudstack.api.APICom
  import org.apache.cloudstack.api.ApiConstants;
  import org.apache.cloudstack.api.ApiErrorCode;
  import org.apache.cloudstack.api.BaseAsyncCmd;
+ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
  import org.apache.cloudstack.api.Parameter;
 +import org.apache.cloudstack.api.ResponseObject.ResponseView;
  import org.apache.cloudstack.api.ServerApiException;
  import org.apache.cloudstack.api.response.NetworkOfferingResponse;
  import org.apache.cloudstack.api.response.NetworkResponse;
@@@ -41,8 -37,8 +42,8 @@@ import com.cloud.offering.NetworkOfferi
  import com.cloud.user.Account;
  import com.cloud.user.User;
  
 -@APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class)
 +@APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = { AclEntityType.Network })
- public class UpdateNetworkCmd extends BaseAsyncCmd {
+ public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd {
      public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName());
  
      private static final String s_name = "updatenetworkresponse";
@@@ -147,12 -141,12 +148,12 @@@
  
          Network result =
              _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(),
-                 getChangeCidr(), getGuestVmCidr(), getDisplayNetwork());
 -                getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), this.getCustomId());
++                getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId());
  
          if (result != null) {
-             NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
 -            NetworkResponse response = _responseGenerator.createNetworkResponse(result);
++            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
              response.setResponseName(getCommandName());
 -            this.setResponseObject(response);
 +            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
          }
@@@ -194,4 -188,11 +195,11 @@@
      public Long getSyncObjId() {
          return id;
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), Network.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), Network.class);
+         }
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
index 4b541f4,0639477..28d7c0ea
--- a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
@@@ -154,4 -146,12 +154,12 @@@ public class UpdateVMCmd extends BaseCu
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm");
          }
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), UserVm.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), UserVm.class);
+ 
+         }
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
index f63a53c,65d2849..3fa24cf
--- a/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
@@@ -15,11 -15,7 +15,12 @@@
  // specific language governing permissions and limitations
  // under the License.
  package org.apache.cloudstack.api.command.user.volume;
+ 
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.acl.AclEntityType;
 +import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 +import org.apache.cloudstack.api.ACL;
  import org.apache.cloudstack.api.APICommand;
  import org.apache.cloudstack.api.ApiCommandJobType;
  import org.apache.cloudstack.api.ApiConstants;
@@@ -153,4 -148,12 +154,12 @@@ public class UpdateVolumeCmd extends Ba
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
          }
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), Volume.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), Volume.class);
+         }
+     }
+ 
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
index ed63225,3f24a2f..16829a2
--- a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
@@@ -25,17 -20,18 +25,18 @@@ import org.apache.cloudstack.api.APICom
  import org.apache.cloudstack.api.ApiConstants;
  import org.apache.cloudstack.api.ApiErrorCode;
  import org.apache.cloudstack.api.BaseAsyncCmd;
+ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
  import org.apache.cloudstack.api.Parameter;
 +import org.apache.cloudstack.api.ResponseObject.ResponseView;
  import org.apache.cloudstack.api.ServerApiException;
  import org.apache.cloudstack.api.response.VpcResponse;
 -import org.apache.log4j.Logger;
  
  import com.cloud.event.EventTypes;
  import com.cloud.network.vpc.Vpc;
  import com.cloud.user.Account;
  
 -@APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class)
 +@APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = { AclEntityType.Vpc })
- public class UpdateVPCCmd extends BaseAsyncCmd{
+ public class UpdateVPCCmd extends BaseAsyncCustomIdCmd {
      public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName());
      private static final String Name = "updatevpcresponse";
  
@@@ -88,11 -84,11 +89,11 @@@
  
      @Override
      public void execute() {
-         Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText());
 -        Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), this.getCustomId());
++        Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId());
          if (result != null) {
 -            VpcResponse response = _responseGenerator.createVpcResponse(result);
 +            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Restricted, result);
              response.setResponseName(getCommandName());
 -            this.setResponseObject(response);
 +            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
          }
@@@ -117,4 -113,11 +118,11 @@@
      public Long getSyncObjId() {
          return getId();
      }
+ 
+     @Override
+     public void checkUuid() {
 -        if (this.getCustomId() != null) {
 -            _uuidMgr.checkUuid(this.getCustomId(), Vpc.class);
++        if (getCustomId() != null) {
++            _uuidMgr.checkUuid(getCustomId(), Vpc.class);
+         }
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/client/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --cc engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 8684876,ce40762..1227210
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@@ -2447,8 -2430,12 +2448,12 @@@ public class NetworkOrchestrator extend
              return null;
          }
  
+         NetworkElement element = _networkModel.getElementImplementingProvider(DhcpProvider);
+         if ( element instanceof DhcpServiceProvider ) {
 -            return (DhcpServiceProvider)_networkModel.getElementImplementingProvider(DhcpProvider);
 +        return (DhcpServiceProvider)_networkModel.getElementImplementingProvider(DhcpProvider);
- 
+         } else {
+             return null;
+         }
      }
  
      protected boolean isSharedNetworkWithServices(Network network) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
index 27d00af,9650249..1c12ce6
--- a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
+++ b/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
@@@ -210,8 -209,7 +210,12 @@@ public class AutoScaleVmGroupVO impleme
          return uuid;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.AutoScaleVmGroup;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
index e5db2c9,9a8fbd8..e718a2b
--- a/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
+++ b/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
@@@ -92,7 -91,7 +92,7 @@@ public class AutoScaleVmProfileVO imple
  
      public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId, String otherDeployParams, Map counterParamList,
              Integer destroyVmGraceperiod, long autoscaleUserId) {
--        this.uuid = UUID.randomUUID().toString();
++        uuid = UUID.randomUUID().toString();
          this.zoneId = zoneId;
          this.domainId = domainId;
          this.accountId = accountId;
@@@ -147,7 -146,7 +147,7 @@@
      }
  
      public void setCounterParams(String counterParam) {
--        this.counterParams = counterParam;
++        counterParams = counterParam;
      }
  
      public void setCounterParamsForUpdate(Map counterParamList) {
@@@ -218,8 -217,7 +218,13 @@@
          return autoscaleUserId;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.AutoScaleVmProfile;
 +    }
++
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
index d7cb864,f9967ec..21e4f03
--- a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
+++ b/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
@@@ -117,13 -113,7 +115,13 @@@ public class MonitoringServiceVO implem
          return defaultService;
      }
  
-     public String getProcessname() {
-         return processname;
+     public String getProcessName() {
+         return processName;
      }
 +
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.MonitorService;
 +    }
 +
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
index 678ea4a,c892949..f546bb7
--- a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
+++ b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
@@@ -151,8 -149,7 +151,12 @@@ public class RemoteAccessVpnVO implemen
          return vpcId;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.RemoteAccessVpn;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
index e3e0433,7f1d0aa..b092a4a
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
@@@ -158,8 -156,7 +158,12 @@@ public class Site2SiteVpnConnectionVO i
          this.passive = passive;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.Site2SiteVpnConnection;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
index 626572e,5e8c6b6..c3ad360
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
@@@ -116,8 -113,7 +116,12 @@@ public class Site2SiteVpnGatewayVO impl
          return accountId;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.Site2SiteVpnGateway;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/schema/src/com/cloud/network/vpc/VpcVO.java
----------------------------------------------------------------------
diff --cc engine/schema/src/com/cloud/network/vpc/VpcVO.java
index 910a8c4,5f3528d..dc4f80e
--- a/engine/schema/src/com/cloud/network/vpc/VpcVO.java
+++ b/engine/schema/src/com/cloud/network/vpc/VpcVO.java
@@@ -78,7 -77,7 +79,7 @@@ public class VpcVO implements Vpc 
      boolean restartRequired = false;
  
      public VpcVO() {
--        this.uuid = UUID.randomUUID().toString();
++        uuid = UUID.randomUUID().toString();
      }
  
      public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr, String networkDomain) {
@@@ -88,10 -87,10 +89,10 @@@
          this.accountId = accountId;
          this.domainId = domainId;
          this.cidr = cidr;
--        this.uuid = UUID.randomUUID().toString();
--        this.state = State.Enabled;
++        uuid = UUID.randomUUID().toString();
++        state = State.Enabled;
          this.networkDomain = networkDomain;
--        this.vpcOfferingId = vpcOffId;
++        vpcOfferingId = vpcOffId;
      }
  
      @Override
@@@ -180,8 -179,7 +181,12 @@@
          return restartRequired;
      }
  
+     public void setUuid(String uuid) {
+         this.uuid = uuid;
+     }
++
 +    @Override
 +    public AclEntityType getEntityType() {
 +        return AclEntityType.Vpc;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------
diff --cc engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
index 87bb44d,669a075..b5573dd
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
@@@ -287,7 -286,10 +287,10 @@@ public class SnapshotObject implements 
              } else if (answer instanceof CopyCmdAnswer) {
                  SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer)answer).getNewData();
                  snapshotStore.setInstallPath(snapshotTO.getPath());
+                 if (snapshotTO.getPhysicalSize() != null) {
+                     // For S3 delta snapshot, physical size is currently not set
 -                    snapshotStore.setSize(snapshotTO.getPhysicalSize());
 +                snapshotStore.setSize(snapshotTO.getPhysicalSize());
+                 }
                  if (snapshotTO.getParentSnapshotPath() == null) {
                      snapshotStore.setParentSnapshotId(0L);
                  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 5f02004,49fee93..bf45d8f
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@@ -2877,29 -2875,44 +2877,44 @@@ public class ConfigurationManagerImpl e
                      continue;
                  }
                  // from here, subnet overlaps
-                 if (!NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
-                     throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName()
-                             + " has overlapped with the subnet. Please specify a different gateway/netmask.");
+                 if ( !vlanId.equals(vlan.getVlanTag()) ) {
+                     boolean overlapped = false;
+                     if( network.getTrafficType() == TrafficType.Public ) {
+                         overlapped = true;
+                     } else {
+                         Long nwId = vlan.getNetworkId();
+                         if ( nwId != null ) {
+                             Network nw = _networkModel.getNetwork(nwId);
+                             if ( nw != null && nw.getTrafficType() == TrafficType.Public ) {
+                                 overlapped = true;
+                             }
 -                        }
 +                }
-                 if (vlan.getNetworkId() != networkId) {
-                     throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId() + " in zone " + zone.getName()
-                             + " . Please specify a different gateway/netmask.");
  
 -                    }
 +                }
+                     if ( overlapped ) {
+                         throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
+                                 + " in zone " + zone.getName()
+                                 + " has overlapped with the subnet. Please specify a different gateway/netmask.");
+                     }
+                 } else {
+ 
 -                    String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
 -                    String otherVlanStartIP = otherVlanIpRange[0];
 -                    String otherVlanEndIP = null;
 -                    if (otherVlanIpRange.length > 1) {
 -                        otherVlanEndIP = otherVlanIpRange[1];
 -                    }
 +                String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
 +                String otherVlanStartIP = otherVlanIpRange[0];
 +                String otherVlanEndIP = null;
 +                if (otherVlanIpRange.length > 1) {
 +                    otherVlanEndIP = otherVlanIpRange[1];
 +                }
  
-                 //extend IP range
+                     // extend IP range
 -                    if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
 +                if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
-                     throw new InvalidParameterValueException("The IP range has already been added with gateway " + otherVlanGateway + " ,and netmask " + otherVlanNetmask
-                             + ", Please specify the gateway/netmask if you want to extend ip range");
+                         throw new InvalidParameterValueException("The IP range has already been added with gateway "
+                                 + otherVlanGateway + " ,and netmask " + otherVlanNetmask
+                                 + ", Please specify the gateway/netmask if you want to extend ip range" );
 -                    }
 -                    if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
 +                }
 +                if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
-                     throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP.");
+                         throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." +
+                                 " Please specify a different start IP/end IP.");
+                     }
                  }
              }
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/IpAddressManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/IpAddressManagerImpl.java
index 5e2046c,6596074..dbec06f
--- a/server/src/com/cloud/network/IpAddressManagerImpl.java
+++ b/server/src/com/cloud/network/IpAddressManagerImpl.java
@@@ -657,129 -654,129 +654,129 @@@ public class IpAddressManagerImpl exten
          IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {
              @Override
              public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
 -                StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
 -                boolean fetchFromDedicatedRange = false;
 -                List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
 -                List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
 -
 -                SearchCriteria<IPAddressVO> sc = null;
 -                if (podId != null) {
 -                    sc = AssignIpAddressFromPodVlanSearch.create();
 -                    sc.setJoinParameters("podVlanMapSB", "podId", podId);
 -                    errorMessage.append(" pod id=" + podId);
 -                } else {
 -                    sc = AssignIpAddressSearch.create();
 -                    errorMessage.append(" zone id=" + dcId);
 -                }
 +        StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
 +        boolean fetchFromDedicatedRange = false;
 +        List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
 +        List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
 +
 +        SearchCriteria<IPAddressVO> sc = null;
 +        if (podId != null) {
 +            sc = AssignIpAddressFromPodVlanSearch.create();
 +            sc.setJoinParameters("podVlanMapSB", "podId", podId);
 +            errorMessage.append(" pod id=" + podId);
 +        } else {
 +            sc = AssignIpAddressSearch.create();
 +            errorMessage.append(" zone id=" + dcId);
 +        }
  
 -                // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
 -                // Otherwise fetch IP from the system pool
 -                List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(owner.getId());
 -                for (AccountVlanMapVO map : maps) {
 -                    if (vlanDbIds == null || vlanDbIds.contains(map.getVlanDbId()))
 -                        dedicatedVlanDbIds.add(map.getVlanDbId());
 -                }
 -                List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(dcId);
 -                for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
 -                    if (vlanDbIds == null || vlanDbIds.contains(nonDedicatedVlan.getId()))
 -                        nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
 -                }
 -                if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
 -                    fetchFromDedicatedRange = true;
 -                    sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
 +        // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
 +        // Otherwise fetch IP from the system pool
 +        List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(owner.getId());
 +        for (AccountVlanMapVO map : maps) {
 +            if (vlanDbIds == null || vlanDbIds.contains(map.getVlanDbId()))
 +                dedicatedVlanDbIds.add(map.getVlanDbId());
 +        }
 +        List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(dcId);
 +        for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
 +            if (vlanDbIds == null || vlanDbIds.contains(nonDedicatedVlan.getId()))
 +                nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
 +        }
 +        if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
 +            fetchFromDedicatedRange = true;
 +            sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
-                     errorMessage.append(", vlanId id=" + Arrays.toString(dedicatedVlanDbIds.toArray()));
+                     errorMessage.append(", vlanId id=" + dedicatedVlanDbIds.toArray());
 -                } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
 -                    sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
 +        } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
 +            sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
-                     errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
+                     errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
 -                } else {
 -                    if (podId != null) {
 -                        InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 -                        ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
 -                        throw ex;
 -                    }
 -                    s_logger.warn(errorMessage.toString());
 -                    InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 -                    ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
 -                    throw ex;
 -                }
 +        } else {
 +            if (podId != null) {
 +                InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 +                ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
 +                throw ex;
 +            }
 +            s_logger.warn(errorMessage.toString());
 +            InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 +            ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
 +            throw ex;
 +        }
  
 -                sc.setParameters("dc", dcId);
 +        sc.setParameters("dc", dcId);
  
 -                DataCenter zone = _entityMgr.findById(DataCenter.class, dcId);
 +        DataCenter zone = _entityMgr.findById(DataCenter.class, dcId);
  
 -                // for direct network take ip addresses only from the vlans belonging to the network
 -                if (vlanUse == VlanType.DirectAttached) {
 -                    sc.setJoinParameters("vlan", "networkId", guestNetworkId);
 -                    errorMessage.append(", network id=" + guestNetworkId);
 -                }
 -                sc.setJoinParameters("vlan", "type", vlanUse);
 +        // for direct network take ip addresses only from the vlans belonging to the network
 +        if (vlanUse == VlanType.DirectAttached) {
 +            sc.setJoinParameters("vlan", "networkId", guestNetworkId);
 +            errorMessage.append(", network id=" + guestNetworkId);
 +        }
 +        sc.setJoinParameters("vlan", "type", vlanUse);
  
 -                if (requestedIp != null) {
 -                    sc.addAnd("address", SearchCriteria.Op.EQ, requestedIp);
 -                    errorMessage.append(": requested ip " + requestedIp + " is not available");
 -                }
 +        if (requestedIp != null) {
 +            sc.addAnd("address", SearchCriteria.Op.EQ, requestedIp);
 +            errorMessage.append(": requested ip " + requestedIp + " is not available");
 +        }
  
 -                Filter filter = new Filter(IPAddressVO.class, "vlanId", true, 0l, 1l);
 +        Filter filter = new Filter(IPAddressVO.class, "vlanId", true, 0l, 1l);
  
 -                List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true);
 +        List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true);
  
 -                // If all the dedicated IPs of the owner are in use fetch an IP from the system pool
 -                if (addrs.size() == 0 && fetchFromDedicatedRange) {
 -                    // Verify if account is allowed to acquire IPs from the system
 -                    boolean useSystemIps = UseSystemPublicIps.valueIn(owner.getId());
 -                    if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
 -                        fetchFromDedicatedRange = false;
 -                        sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
 +        // If all the dedicated IPs of the owner are in use fetch an IP from the system pool
 +        if (addrs.size() == 0 && fetchFromDedicatedRange) {
 +            // Verify if account is allowed to acquire IPs from the system
 +            boolean useSystemIps = UseSystemPublicIps.valueIn(owner.getId());
 +            if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
 +                fetchFromDedicatedRange = false;
 +                sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
-                         errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
+                         errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
 -                        addrs = _ipAddressDao.lockRows(sc, filter, true);
 -                    }
 -                }
 +                addrs = _ipAddressDao.lockRows(sc, filter, true);
 +            }
 +        }
  
 -                if (addrs.size() == 0) {
 -                    if (podId != null) {
 -                        InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 -                        // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
 -                        ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
 -                        throw ex;
 -                    }
 -                    s_logger.warn(errorMessage.toString());
 -                    InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 -                    ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
 -                    throw ex;
 -                }
 +        if (addrs.size() == 0) {
 +            if (podId != null) {
 +                InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 +                // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
 +                ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
 +                throw ex;
 +            }
 +            s_logger.warn(errorMessage.toString());
 +            InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 +            ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
 +            throw ex;
 +        }
  
 -                assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
 +        assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
  
 -                if (!fetchFromDedicatedRange) {
 -                    // Check that the maximum number of public IPs for the given accountId will not be exceeded
 -                    try {
 -                        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
 -                    } catch (ResourceAllocationException ex) {
 -                        s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
 -                        throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
 -                    }
 -                }
 +        if (!fetchFromDedicatedRange) {
 +            // Check that the maximum number of public IPs for the given accountId will not be exceeded
 +            try {
 +                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
 +            } catch (ResourceAllocationException ex) {
 +                s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
 +                throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
 +            }
 +        }
  
 -                IPAddressVO addr = addrs.get(0);
 -                addr.setSourceNat(sourceNat);
 -                addr.setAllocatedTime(new Date());
 -                addr.setAllocatedInDomainId(owner.getDomainId());
 -                addr.setAllocatedToAccountId(owner.getId());
 -                addr.setSystem(isSystem);
 +        IPAddressVO addr = addrs.get(0);
 +        addr.setSourceNat(sourceNat);
 +        addr.setAllocatedTime(new Date());
 +        addr.setAllocatedInDomainId(owner.getDomainId());
 +        addr.setAllocatedToAccountId(owner.getId());
 +        addr.setSystem(isSystem);
  
 -                if (assign) {
 -                    markPublicIpAsAllocated(addr);
 -                } else {
 -                    addr.setState(IpAddress.State.Allocating);
 -                }
 -                addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
 +        if (assign) {
 +            markPublicIpAsAllocated(addr);
 +        } else {
 +            addr.setState(IpAddress.State.Allocating);
 +        }
 +        addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
  
 -                if (vlanUse != VlanType.DirectAttached) {
 -                    addr.setAssociatedWithNetworkId(guestNetworkId);
 -                    addr.setVpcId(vpcId);
 -                }
 +        if (vlanUse != VlanType.DirectAttached) {
 +            addr.setAssociatedWithNetworkId(guestNetworkId);
 +            addr.setVpcId(vpcId);
 +        }
  
 -                _ipAddressDao.update(addr.getId(), addr);
 +        _ipAddressDao.update(addr.getId(), addr);
  
                  return addr;
              }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/NetworkServiceImpl.java
index 474f510,bcadd69..41cc2ed
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@@ -1989,9 -1984,13 +1989,13 @@@ public class NetworkServiceImpl extend
              network.setDisplayText(displayText);
          }
  
+         if (customId != null) {
+             network.setUuid(customId);
+         }
+ 
          // display flag is not null and has changed
          if (displayNetwork != null && displayNetwork != network.getDisplayNetwork()) {
 -            if (!_accountMgr.isRootAdmin(callerAccount.getType())) {
 +            if (!_accountMgr.isRootAdmin(callerAccount.getId())) {
                  throw new PermissionDeniedException("Only admin allowed to update displaynetwork parameter");
              }
  
@@@ -4032,7 -4031,30 +4036,30 @@@
  
      @Inject
      public void setNetworkGurus(List<NetworkGuru> networkGurus) {
 -        this._networkGurus = networkGurus;
 +        _networkGurus = networkGurus;
      }
  
+     @Override
+     @ActionEvent(eventType = EventTypes.EVENT_NET_IP_UPDATE, eventDescription = "updating public ip address", async = true)
+     public IpAddress updateIP(Long id, String customId) {
+         Account caller = CallContext.current().getCallingAccount();
+         IPAddressVO ipVO = _ipAddressDao.findById(id);
+         if (ipVO == null) {
+             throw new InvalidParameterValueException("Unable to find ip address by id");
+         }
+ 
+         // verify permissions
+         if (ipVO.getAllocatedToAccountId() != null) {
+             _accountMgr.checkAccess(caller, null, true, ipVO);
+         } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+             throw new PermissionDeniedException("Only Root admin can update non-allocated ip addresses");
+         }
+ 
+         if (customId != null) {
+             ipVO.setUuid(customId);
+         }
+         _ipAddressDao.update(id, ipVO);
+         return _ipAddressDao.findById(id);
+     }
+ 
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
index 2ab34c5,ec43883..ef3bba9
--- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@@ -33,7 -29,12 +33,9 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
  import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
  import org.apache.cloudstack.context.CallContext;
 -import org.apache.commons.lang.StringUtils;
 -import org.apache.log4j.Logger;
 -import org.springframework.stereotype.Component;
  
+ import com.cloud.event.ActionEvent;
+ import com.cloud.event.EventTypes;
  import com.cloud.exception.InvalidParameterValueException;
  import com.cloud.exception.ResourceUnavailableException;
  import com.cloud.network.Network;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
index 71a639b,0b33ae3..446e385
--- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
@@@ -724,7 -725,24 +729,24 @@@ public class RemoteAccessVpnManagerImp
      }
  
      public void setVpnServiceProviders(List<RemoteAccessVPNServiceProvider> vpnServiceProviders) {
 -        this._vpnServiceProviders = vpnServiceProviders;
 +        _vpnServiceProviders = vpnServiceProviders;
      }
  
+     @Override
+     @ActionEvent(eventType = EventTypes.EVENT_REMOTE_ACCESS_VPN_UPDATE, eventDescription = "updating remote access vpn", async = true)
+     public RemoteAccessVpn updateRemoteAccessVpn(long id, String customId) {
+         final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findById(id);
+         if (vpn == null) {
+             throw new InvalidParameterValueException("Can't find remote access vpn by id " + id);
+         }
+ 
+         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, vpn);
+         if (customId != null) {
+             vpn.setUuid(customId);
+         }
+ 
+         _remoteAccessVpnDao.update(vpn.getId(), vpn);
+         return _remoteAccessVpnDao.findById(id);
+     }
+ 
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index d296db1,2f6ad6c..03a13c3
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
@@@ -790,6 -780,43 +789,43 @@@ public class Site2SiteVpnManagerImpl ex
  
      @Inject
      public void setS2sProviders(List<Site2SiteVpnServiceProvider> s2sProviders) {
 -        this._s2sProviders = s2sProviders;
 +        _s2sProviders = s2sProviders;
      }
+ 
+     @Override
+     @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_UPDATE, eventDescription = "creating s2s vpn gateway", async = true)
+     public Site2SiteVpnConnection updateVpnConnection(long id, String customId) {
+         Account caller = CallContext.current().getCallingAccount();
+         Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
+         if (conn == null) {
+             throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id);
+         }
+ 
+         _accountMgr.checkAccess(caller, null, false, conn);
+         if (customId != null) {
+             conn.setUuid(customId);
+         }
+ 
+         _vpnConnectionDao.update(id, conn);
+         return _vpnConnectionDao.findById(id);
+     }
+ 
+     @Override
+     @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_UPDATE, eventDescription = "updating s2s vpn gateway", async = true)
+     public Site2SiteVpnGateway updateVpnGateway(Long id, String customId) {
+         Account caller = CallContext.current().getCallingAccount();
+ 
+         Site2SiteVpnGatewayVO vpnGateway = _vpnGatewayDao.findById(id);
+         if (vpnGateway == null) {
+             throw new InvalidParameterValueException("Fail to find vpn gateway with " + id);
+         }
+ 
+         _accountMgr.checkAccess(caller, null, false, vpnGateway);
+         if (customId != null) {
+             vpnGateway.setUuid(customId);
+         }
+         _vpnGatewayDao.update(id, vpnGateway);
+         return _vpnGatewayDao.findById(id);
+ 
+     }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ManagementServerImpl.java
index 0fe7f17,2a08ddc4..bd84692
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@@ -433,8 -434,11 +438,11 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
  import org.apache.cloudstack.api.command.user.vpn.RemoveVpnUserCmd;
  import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
+ import org.apache.cloudstack.api.command.user.vpn.UpdateRemoteAccessVpnCmd;
+ import org.apache.cloudstack.api.command.user.vpn.UpdateVpnConnectionCmd;
  import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
+ import org.apache.cloudstack.api.command.user.vpn.UpdateVpnGatewayCmd;
 -import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
 +import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
  import org.apache.cloudstack.config.Configuration;
  import org.apache.cloudstack.context.CallContext;
  import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/TemplateManagerImpl.java
index c84a9b7,70e4a49..dde18b9
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@@ -74,9 -72,6 +74,8 @@@ import org.apache.cloudstack.framework.
  import org.apache.cloudstack.framework.config.ConfigKey;
  import org.apache.cloudstack.framework.config.Configurable;
  import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
- import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 +import org.apache.cloudstack.framework.messagebus.MessageBus;
 +import org.apache.cloudstack.framework.messagebus.PublishScope;
  import org.apache.cloudstack.managed.context.ManagedContextRunnable;
  import org.apache.cloudstack.storage.command.AttachCommand;
  import org.apache.cloudstack.storage.command.CommandResult;
@@@ -198,118 -175,78 +180,82 @@@ public class TemplateManagerImpl extend
      private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class);
  
      @Inject
-     VMTemplateDao _tmpltDao;
+     private VMTemplateDao _tmpltDao;
      @Inject
-     TemplateDataStoreDao _tmplStoreDao;
+     private TemplateDataStoreDao _tmplStoreDao;
      @Inject
-     VMTemplatePoolDao _tmpltPoolDao;
+     private VMTemplatePoolDao _tmpltPoolDao;
      @Inject
-     VMTemplateZoneDao _tmpltZoneDao;
+     private VMTemplateZoneDao _tmpltZoneDao;
      @Inject
-     protected UserVmDetailsDao _vmDetailsDao;
+     private VMInstanceDao _vmInstanceDao;
      @Inject
-     protected VMTemplateDetailsDao _templateDetailsDao;
+     private PrimaryDataStoreDao _poolDao;
      @Inject
-     VMInstanceDao _vmInstanceDao;
+     private StoragePoolHostDao _poolHostDao;
      @Inject
-     PrimaryDataStoreDao _poolDao;
+     private AccountDao _accountDao;
      @Inject
-     StoragePoolHostDao _poolHostDao;
+     private AgentManager _agentMgr;
      @Inject
-     EventDao _eventDao;
+     private AccountManager _accountMgr;
      @Inject
-     DownloadMonitor _downloadMonitor;
+     private HostDao _hostDao;
      @Inject
-     UploadMonitor _uploadMonitor;
+     private DataCenterDao _dcDao;
      @Inject
-     UserAccountDao _userAccountDao;
+     private UserVmDao _userVmDao;
      @Inject
-     AccountDao _accountDao;
+     private VolumeDao _volumeDao;
      @Inject
-     UserDao _userDao;
+     private SnapshotDao _snapshotDao;
      @Inject
-     AgentManager _agentMgr;
+     private ConfigurationDao _configDao;
      @Inject
-     AccountManager _accountMgr;
+     private DomainDao _domainDao;
      @Inject
-     HostDao _hostDao;
+     private GuestOSDao _guestOSDao;
      @Inject
-     DataCenterDao _dcDao;
+     private StorageManager _storageMgr;
      @Inject
-     UserVmDao _userVmDao;
+     private UsageEventDao _usageEventDao;
      @Inject
-     VolumeDao _volumeDao;
+     private AccountService _accountService;
      @Inject
-     SnapshotDao _snapshotDao;
+     private ResourceLimitService _resourceLimitMgr;
      @Inject
-     ConfigurationDao _configDao;
+     private LaunchPermissionDao _launchPermissionDao;
      @Inject
-     ClusterDao _clusterDao;
+     private ProjectManager _projectMgr;
      @Inject
-     DomainDao _domainDao;
+     private VolumeDataFactory _volFactory;
      @Inject
-     UploadDao _uploadDao;
+     private TemplateDataFactory _tmplFactory;
      @Inject
-     protected GuestOSDao _guestOSDao;
+     private SnapshotDataFactory _snapshotFactory;
      @Inject
-     StorageManager _storageMgr;
+     private TemplateService _tmpltSvr;
      @Inject
-     AsyncJobManager _asyncMgr;
+     private DataStoreManager _dataStoreMgr;
      @Inject
-     UserVmManager _vmMgr;
+     private VolumeOrchestrationService _volumeMgr;
      @Inject
-     UsageEventDao _usageEventDao;
+     private EndPointSelector _epSelector;
      @Inject
-     HypervisorGuruManager _hvGuruMgr;
-     @Inject
-     AccountService _accountService;
-     @Inject
-     ResourceLimitService _resourceLimitMgr;
-     @Inject
-     SecondaryStorageVmManager _ssvmMgr;
-     @Inject
-     LaunchPermissionDao _launchPermissionDao;
-     @Inject
-     ProjectManager _projectMgr;
-     @Inject
-     VolumeDataFactory _volFactory;
-     @Inject
-     TemplateDataFactory _tmplFactory;
-     @Inject
-     SnapshotDataFactory _snapshotFactory;
-     @Inject
-     TemplateService _tmpltSvr;
-     @Inject
-     DataStoreManager _dataStoreMgr;
-     @Inject
-     protected ResourceManager _resourceMgr;
-     @Inject
-     VolumeOrchestrationService _volumeMgr;
-     @Inject
-     ImageStoreDao _imageStoreDao;
-     @Inject
-     EndPointSelector _epSelector;
-     @Inject
-     UserVmJoinDao _userVmJoinDao;
-     @Inject
-     VMTemplateHostDao _vmTemplateHostDao;
+     private UserVmJoinDao _userVmJoinDao;
 +
 +    @Inject
-     ConfigurationServer _configServer;
-     @Inject
 +    MessageBus _messageBus;
 +
-     int _primaryStorageDownloadWait;
-     int _storagePoolMaxWaitSeconds = 3600;
-     boolean _disableExtraction = false;
-     ExecutorService _preloadExecutor;
+     private boolean _disableExtraction = false;
+     private ExecutorService _preloadExecutor;
  
-     protected List<TemplateAdapter> _adapters;
+     private List<TemplateAdapter> _adapters;
  
      @Inject
-     StorageCacheManager cacheMgr;
+     private StorageCacheManager cacheMgr;
      @Inject
-     EndPointSelector selector;
+     private EndPointSelector selector;
  
      private TemplateAdapter getAdapter(HypervisorType type) {
          TemplateAdapter adapter = null;
@@@ -432,9 -369,9 +378,9 @@@
          if (isISO) {
              desc = Upload.Type.ISO.toString();
          }
-         eventId = (eventId == null ? 0 : eventId);
+         eventId = eventId == null ? 0 : eventId;
  
 -        if (!_accountMgr.isRootAdmin(caller.getType()) && _disableExtraction) {
 +        if (!_accountMgr.isRootAdmin(caller.getId()) && _disableExtraction) {
              throw new PermissionDeniedException("Extraction has been disabled by admin");
          }
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index 0089476,f6f20cc..2957bac
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -4559,16 -4735,19 +4557,19 @@@ public class UserVmManagerImpl extends 
          _volsDao.detachVolume(root.getId());
          volumeMgr.destroyVolume(root);
  
-         // For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume
+         // For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage
          if (vm.getHypervisorType() == HypervisorType.VMware) {
+             VolumeInfo volumeInStorage = volFactory.getVolume(root.getId());
+             if (volumeInStorage != null) {
 -                s_logger.info("Expunging volume " + root.getId() + " from primary data store");
 -                AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
 -                try {
 -                    future.get();
 -                } catch (Exception e) {
 -                    s_logger.debug("Failed to expunge volume:" + root.getId(), e);
 -                }
 +            s_logger.info("Expunging volume " + root.getId() + " from primary data store");
 +            AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
 +            try {
 +                future.get();
 +            } catch (Exception e) {
 +                s_logger.debug("Failed to expunge volume:" + root.getId(), e);
              }
          }
++        }
  
          if (template.getEnablePassword()) {
              String password = generateRandomPassword();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b58a45e/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
----------------------------------------------------------------------


[15/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-5932: update the definitions with the new debian version


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0ce48884
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0ce48884
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0ce48884

Branch: refs/heads/rbac
Commit: 0ce488849ddad65ec0f37f5bbc03b619bb959d58
Parents: 18191ce
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 10:52:36 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 10:52:36 2014 +0100

----------------------------------------------------------------------
 tools/appliance/definitions/systemvm64template/definition.rb | 2 +-
 tools/appliance/definitions/systemvmtemplate/definition.rb   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0ce48884/tools/appliance/definitions/systemvm64template/definition.rb
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvm64template/definition.rb b/tools/appliance/definitions/systemvm64template/definition.rb
index ba2659c..e0b6b00 100644
--- a/tools/appliance/definitions/systemvm64template/definition.rb
+++ b/tools/appliance/definitions/systemvm64template/definition.rb
@@ -3,7 +3,7 @@ Veewee::Definition.declare({
   :memory_size=> '256',
   :disk_size => '2500', :disk_format => 'VDI', :hostiocache => 'off',
   :os_type_id => 'Debian_64',
-  :iso_file => "debian-7.0.0-amd64-netinst.iso",
+  :iso_file => "debian-7.3.0-amd64-netinst.iso",
   :iso_src => "http://ftp.acc.umu.se/mirror/cdimage/release/7.3.0/amd64/iso-cd/debian-7.3.0-amd64-netinst.iso",
   :iso_md5 => "72473e8a5e65b61acc7efde90d9f71d1",
   :iso_download_timeout => "1000",

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0ce48884/tools/appliance/definitions/systemvmtemplate/definition.rb
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/definition.rb b/tools/appliance/definitions/systemvmtemplate/definition.rb
index 1717552..6f6a856 100644
--- a/tools/appliance/definitions/systemvmtemplate/definition.rb
+++ b/tools/appliance/definitions/systemvmtemplate/definition.rb
@@ -3,7 +3,7 @@ Veewee::Definition.declare({
   :memory_size=> '256',
   :disk_size => '2500', :disk_format => 'VDI', :hostiocache => 'off',
   :os_type_id => 'Debian',
-  :iso_file => "debian-7.0.0-i386-netinst.iso",
+  :iso_file => "debian-7.3.0-i386-netinst.iso",
   :iso_src => "http://ftp.acc.umu.se/mirror/cdimage/release/7.3.0/i386/iso-cd/debian-7.3.0-i386-netinst.iso",
   :iso_md5 => "04c58f30744e64a0459caf7d7cace479",
   :iso_download_timeout => "1000",


[06/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
new file mode 100755
index 0000000..ee50647
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
@@ -0,0 +1,312 @@
+// 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.storage.resource;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status.Event;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.resource.Discoverer;
+import com.cloud.resource.DiscovererBase;
+import com.cloud.resource.ServerResource;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.VMTemplateZoneVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VMTemplateZoneDao;
+import com.cloud.storage.resource.DummySecondaryStorageResource;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.net.NfsUtils;
+import com.cloud.utils.script.Script;
+
+/**
+ * SecondaryStorageDiscoverer is used to discover secondary
+ * storage servers and make sure everything it can do is
+ * correct.
+ */
+@Local(value = Discoverer.class)
+public class SecondaryStorageDiscoverer extends DiscovererBase implements Discoverer {
+    private static final Logger s_logger = Logger.getLogger(SecondaryStorageDiscoverer.class);
+
+    long _timeout = 2 * 60 * 1000; // 2 minutes
+    String _mountParent;
+    boolean _useServiceVM = false;
+
+    Random _random = new Random(System.currentTimeMillis());
+    @Inject
+    protected VMTemplateDao _tmpltDao = null;
+    @Inject
+    protected VMTemplateZoneDao _vmTemplateZoneDao = null;
+    @Inject
+    protected VMTemplateDao _vmTemplateDao = null;
+    @Inject
+    protected AgentManager _agentMgr = null;
+
+    protected SecondaryStorageDiscoverer() {
+    }
+
+    @Override
+    public Map<? extends ServerResource, Map<String, String>>
+        find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) {
+        if (!uri.getScheme().equalsIgnoreCase("nfs") && !uri.getScheme().equalsIgnoreCase("cifs") && !uri.getScheme().equalsIgnoreCase("file") &&
+            !uri.getScheme().equalsIgnoreCase("iso") && !uri.getScheme().equalsIgnoreCase("dummy")) {
+            s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString());
+            return null;
+        }
+
+        if (uri.getScheme().equalsIgnoreCase("nfs") || uri.getScheme().equalsIgnoreCase("cifs") || uri.getScheme().equalsIgnoreCase("iso")) {
+            return createNfsSecondaryStorageResource(dcId, podId, uri);
+        } else if (uri.getScheme().equalsIgnoreCase("file")) {
+            return createLocalSecondaryStorageResource(dcId, podId, uri);
+        } else if (uri.getScheme().equalsIgnoreCase("dummy")) {
+            return createDummySecondaryStorageResource(dcId, podId, uri);
+        } else {
+            return null;
+        }
+    }
+
+    protected Map<? extends ServerResource, Map<String, String>> createNfsSecondaryStorageResource(long dcId, Long podId, URI uri) {
+
+        if (_useServiceVM) {
+            return createDummySecondaryStorageResource(dcId, podId, uri);
+        }
+        String mountStr = NfsUtils.uri2Mount(uri);
+
+        Script script = new Script(true, "mount", _timeout, s_logger);
+        String mntPoint = null;
+        File file = null;
+        do {
+            mntPoint = _mountParent + File.separator + Integer.toHexString(_random.nextInt(Integer.MAX_VALUE));
+            file = new File(mntPoint);
+        } while (file.exists());
+
+        if (!file.mkdirs()) {
+            s_logger.warn("Unable to make directory: " + mntPoint);
+            return null;
+        }
+
+        script.add(mountStr, mntPoint);
+        String result = script.execute();
+        if (result != null && !result.contains("already mounted")) {
+            s_logger.warn("Unable to mount " + uri.toString() + " due to " + result);
+            file.delete();
+            return null;
+        }
+
+        script = new Script(true, "umount", 0, s_logger);
+        script.add(mntPoint);
+        script.execute();
+
+        file.delete();
+
+        Map<NfsSecondaryStorageResource, Map<String, String>> srs = new HashMap<NfsSecondaryStorageResource, Map<String, String>>();
+
+        NfsSecondaryStorageResource storage;
+        if (_configDao.isPremium()) {
+            Class<?> impl;
+            String name = "com.cloud.storage.resource.PremiumSecondaryStorageResource";
+            try {
+                impl = Class.forName(name);
+                final Constructor<?> constructor = impl.getDeclaredConstructor();
+                constructor.setAccessible(true);
+                storage = (NfsSecondaryStorageResource)constructor.newInstance();
+            } catch (final ClassNotFoundException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to ClassNotFoundException");
+                return null;
+            } catch (final SecurityException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to SecurityException");
+                return null;
+            } catch (final NoSuchMethodException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to NoSuchMethodException");
+                return null;
+            } catch (final IllegalArgumentException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalArgumentException");
+                return null;
+            } catch (final InstantiationException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InstantiationException");
+                return null;
+            } catch (final IllegalAccessException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalAccessException");
+                return null;
+            } catch (final InvocationTargetException e) {
+                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InvocationTargetException");
+                return null;
+            }
+        } else {
+            storage = new NfsSecondaryStorageResource();
+        }
+
+        Map<String, String> details = new HashMap<String, String>();
+        details.put("mount.path", mountStr);
+        details.put("orig.url", uri.toString());
+        details.put("mount.parent", _mountParent);
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.putAll(details);
+        params.put("zone", Long.toString(dcId));
+        if (podId != null) {
+            params.put("pod", podId.toString());
+        }
+        params.put("guid", uri.toString());
+        params.put("secondary.storage.vm", "false");
+        params.put("max.template.iso.size", _configDao.getValue("max.template.iso.size"));
+
+        try {
+            storage.configure("Storage", params);
+        } catch (ConfigurationException e) {
+            s_logger.warn("Unable to configure the storage ", e);
+            return null;
+        }
+        srs.put(storage, details);
+
+        return srs;
+    }
+
+    protected Map<? extends ServerResource, Map<String, String>> createLocalSecondaryStorageResource(long dcId, Long podId, URI uri) {
+        Map<LocalSecondaryStorageResource, Map<String, String>> srs = new HashMap<LocalSecondaryStorageResource, Map<String, String>>();
+
+        LocalSecondaryStorageResource storage = new LocalSecondaryStorageResource();
+        storage = ComponentContext.inject(storage);
+
+        Map<String, String> details = new HashMap<String, String>();
+
+        File file = new File(uri);
+        details.put("mount.path", file.getAbsolutePath());
+        details.put("orig.url", uri.toString());
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.putAll(details);
+        params.put("zone", Long.toString(dcId));
+        if (podId != null) {
+            params.put("pod", podId.toString());
+        }
+        params.put("guid", uri.toString());
+
+        try {
+            storage.configure("Storage", params);
+        } catch (ConfigurationException e) {
+            s_logger.warn("Unable to configure the storage ", e);
+            return null;
+        }
+        srs.put(storage, details);
+
+        return srs;
+    }
+
+    protected Map<ServerResource, Map<String, String>> createDummySecondaryStorageResource(long dcId, Long podId, URI uri) {
+        Map<ServerResource, Map<String, String>> srs = new HashMap<ServerResource, Map<String, String>>();
+
+        DummySecondaryStorageResource storage = new DummySecondaryStorageResource(_useServiceVM);
+        storage = ComponentContext.inject(storage);
+
+        Map<String, String> details = new HashMap<String, String>();
+
+        details.put("mount.path", uri.toString());
+        details.put("orig.url", uri.toString());
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.putAll(details);
+        params.put("zone", Long.toString(dcId));
+        if (podId != null) {
+            params.put("pod", podId.toString());
+        }
+        params.put("guid", uri.toString());
+
+        try {
+            storage.configure("Storage", params);
+        } catch (ConfigurationException e) {
+            s_logger.warn("Unable to configure the storage ", e);
+            return null;
+        }
+        srs.put(storage, details);
+
+        return srs;
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        super.configure(name, params);
+
+        _mountParent = _params.get("mount.parent");
+        if (_mountParent == null) {
+            _mountParent = "/mnt";
+        }
+
+        String useServiceVM = _params.get("secondary.storage.vm");
+        if ("true".equalsIgnoreCase(useServiceVM)) {
+            _useServiceVM = true;
+        }
+        return true;
+    }
+
+    @Override
+    public boolean matchHypervisor(String hypervisor) {
+        if (hypervisor.equals("SecondaryStorage")) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public Hypervisor.HypervisorType getHypervisorType() {
+        return Hypervisor.HypervisorType.None;
+    }
+
+    @Override
+    public void postDiscovery(List<HostVO> hosts, long msId) {
+        if (_useServiceVM) {
+            for (HostVO h : hosts) {
+                _agentMgr.agentStatusTransitTo(h, Event.AgentDisconnected, msId);
+            }
+        }
+        for (HostVO h : hosts) {
+            associateTemplatesToZone(h.getId(), h.getDataCenterId());
+        }
+
+    }
+
+    private void associateTemplatesToZone(long hostId, long dcId) {
+        VMTemplateZoneVO tmpltZone;
+
+        List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
+        for (VMTemplateVO vt : allTemplates) {
+            if (vt.isCrossZones()) {
+                tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
+                if (tmpltZone == null) {
+                    VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
+                    _vmTemplateZoneDao.persist(vmTemplateZone);
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
new file mode 100755
index 0000000..93fd8ea
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
@@ -0,0 +1,29 @@
+// 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.storage.resource;
+
+import com.cloud.resource.ServerResource;
+
+/**
+ *
+ * SecondaryStorageServerResource is a generic container to execute commands sent
+ */
+public interface SecondaryStorageResource extends ServerResource {
+
+    public String getRootDir(String cmd);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
new file mode 100644
index 0000000..14ebc71
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
@@ -0,0 +1,24 @@
+// 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.storage.resource;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+
+public interface SecondaryStorageResourceHandler {
+    Answer executeRequest(Command cmd);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManager.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManager.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManager.java
new file mode 100644
index 0000000..d0abe2c
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManager.java
@@ -0,0 +1,108 @@
+// 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.storage.template;
+
+import java.util.Map;
+
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
+import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
+
+import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.Proxy;
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateHostVO;
+import com.cloud.storage.template.TemplateDownloader;
+import com.cloud.storage.template.TemplateProp;
+import com.cloud.utils.component.Manager;
+
+public interface DownloadManager extends Manager {
+
+    /**
+     * Initiate download of a public template
+     * @param id unique id.
+     * @param url  the url from where to download from
+     * @param hvm  whether the template is a hardware virtual machine
+     * @param accountId the accountId of the iso owner (null if public iso)
+     * @param descr    description of the template
+     * @param user username used for authentication to the server
+     * @param password password used for authentication to the server
+     * @param maxDownloadSizeInBytes (optional) max download size for the template, in bytes.
+     * @param resourceType signifying the type of resource like template, volume etc.
+     * @return job-id that can be used to interrogate the status of the download.
+     */
+    public String downloadPublicTemplate(long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+        String installPathPrefix, String templatePath, String userName, String passwd, long maxDownloadSizeInBytes, Proxy proxy, ResourceType resourceType);
+
+    public String downloadS3Template(S3TO s3, long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+        String installPathPrefix, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType);
+
+    /**
+     * Get the status of a download job
+     * @param jobId job Id
+     * @return status of the download job
+     */
+    public TemplateDownloader.Status getDownloadStatus(String jobId);
+
+    /**
+     * Get the status of a download job
+     * @param jobId job Id
+     * @return status of the download job
+     */
+    public VMTemplateHostVO.Status getDownloadStatus2(String jobId);
+
+    /**
+     * Get the download percent of a download job
+     * @param jobId job Id
+     * @return
+     */
+    public int getDownloadPct(String jobId);
+
+    /**
+     * Get the download error if any
+     * @param jobId job Id
+     * @return
+     */
+    public String getDownloadError(String jobId);
+
+    /**
+     * Get the local path for the download
+     * @param jobId job Id
+     * @return
+    public String getDownloadLocalPath(String jobId);
+     */
+
+    /** Handle download commands from the management server
+     * @param cmd cmd from server
+     * @return answer representing status of download.
+     */
+    public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd);
+
+    /**
+    /**
+     * @return list of template info for installed templates
+     */
+    public Map<String, TemplateProp> gatherTemplateInfo(String templateDir);
+
+    /**
+    /**
+     * @return list of volume info for installed volumes
+     */
+    public Map<Long, TemplateProp> gatherVolumeInfo(String volumeDir);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
new file mode 100755
index 0000000..d45a6bb
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
@@ -0,0 +1,1080 @@
+// 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.storage.template;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
+import org.apache.cloudstack.storage.command.DownloadProgressCommand;
+import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
+import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
+
+import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.Proxy;
+import com.cloud.agent.api.to.DataStoreTO;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.exception.InternalErrorException;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.StorageLayer;
+import com.cloud.storage.VMTemplateHostVO;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.template.HttpTemplateDownloader;
+import com.cloud.storage.template.IsoProcessor;
+import com.cloud.storage.template.LocalTemplateDownloader;
+import com.cloud.storage.template.OVAProcessor;
+import com.cloud.storage.template.Processor;
+import com.cloud.storage.template.Processor.FormatInfo;
+import com.cloud.storage.template.QCOW2Processor;
+import com.cloud.storage.template.RawImageProcessor;
+import com.cloud.storage.template.S3TemplateDownloader;
+import com.cloud.storage.template.ScpTemplateDownloader;
+import com.cloud.storage.template.TemplateConstants;
+import com.cloud.storage.template.TemplateDownloader;
+import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
+import com.cloud.storage.template.TemplateDownloader.Status;
+import com.cloud.storage.template.TemplateLocation;
+import com.cloud.storage.template.TemplateProp;
+import com.cloud.storage.template.VhdProcessor;
+import com.cloud.storage.template.VmdkProcessor;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.Script;
+
+@Local(value = DownloadManager.class)
+public class DownloadManagerImpl extends ManagerBase implements DownloadManager {
+    private String _name;
+    StorageLayer _storage;
+    Map<String, Processor> _processors;
+
+    public class Completion implements DownloadCompleteCallback {
+        private final String jobId;
+
+        public Completion(String jobId) {
+            this.jobId = jobId;
+        }
+
+        @Override
+        public void downloadComplete(Status status) {
+            setDownloadStatus(jobId, status);
+        }
+    }
+
+    private static class DownloadJob {
+        private final TemplateDownloader td;
+        private final String tmpltName;
+        private final boolean hvm;
+        private final ImageFormat format;
+        private String tmpltPath;
+        private final String description;
+        private String checksum;
+        private final String installPathPrefix;
+        private long templatesize;
+        private long templatePhysicalSize;
+        private final long id;
+        private final ResourceType resourceType;
+
+        public DownloadJob(TemplateDownloader td, String jobId, long id, String tmpltName, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+                String installPathPrefix, ResourceType resourceType) {
+            super();
+            this.td = td;
+            this.tmpltName = tmpltName;
+            this.format = format;
+            this.hvm = hvm;
+            description = descr;
+            checksum = cksum;
+            this.installPathPrefix = installPathPrefix;
+            templatesize = 0;
+            this.id = id;
+            this.resourceType = resourceType;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        public String getChecksum() {
+            return checksum;
+        }
+
+        public TemplateDownloader getTemplateDownloader() {
+            return td;
+        }
+
+        public String getTmpltName() {
+            return tmpltName;
+        }
+
+        public ImageFormat getFormat() {
+            return format;
+        }
+
+        public boolean isHvm() {
+            return hvm;
+        }
+
+        public long getId() {
+            return id;
+        }
+
+        public ResourceType getResourceType() {
+            return resourceType;
+        }
+
+        public void setTmpltPath(String tmpltPath) {
+            this.tmpltPath = tmpltPath;
+        }
+
+        public String getTmpltPath() {
+            return tmpltPath;
+        }
+
+        public String getInstallPathPrefix() {
+            return installPathPrefix;
+        }
+
+        public void cleanup() {
+            if (td != null) {
+                String dnldPath = td.getDownloadLocalPath();
+                if (dnldPath != null) {
+                    File f = new File(dnldPath);
+                    File dir = f.getParentFile();
+                    f.delete();
+                    if (dir != null) {
+                        dir.delete();
+                    }
+                }
+            }
+
+        }
+
+        public void setTemplatesize(long templatesize) {
+            this.templatesize = templatesize;
+        }
+
+        public long getTemplatesize() {
+            return templatesize;
+        }
+
+        public void setTemplatePhysicalSize(long templatePhysicalSize) {
+            this.templatePhysicalSize = templatePhysicalSize;
+        }
+
+        public long getTemplatePhysicalSize() {
+            return templatePhysicalSize;
+        }
+
+        public void setCheckSum(String checksum) {
+            this.checksum = checksum;
+        }
+    }
+
+    public static final Logger s_logger = Logger.getLogger(DownloadManagerImpl.class);
+    private String _templateDir;
+    private String _volumeDir;
+    private String createTmpltScr;
+    private String createVolScr;
+
+    private ExecutorService threadPool;
+
+    private final Map<String, DownloadJob> jobs = new ConcurrentHashMap<String, DownloadJob>();
+    private String listTmpltScr;
+    private String listVolScr;
+    private int installTimeoutPerGig = 180 * 60 * 1000;
+
+    public void setThreadPool(ExecutorService threadPool) {
+        this.threadPool = threadPool;
+    }
+
+    public void setStorageLayer(StorageLayer storage) {
+        _storage = storage;
+    }
+
+    /**
+     * Get notified of change of job status. Executed in context of downloader
+     * thread
+     *
+     * @param jobId
+     *            the id of the job
+     * @param status
+     *            the status of the job
+     */
+    public void setDownloadStatus(String jobId, Status status) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj == null) {
+            s_logger.warn("setDownloadStatus for jobId: " + jobId + ", status=" + status + " no job found");
+            return;
+        }
+        TemplateDownloader td = dj.getTemplateDownloader();
+        s_logger.info("Download Completion for jobId: " + jobId + ", status=" + status);
+        s_logger.info("local: " + td.getDownloadLocalPath() + ", bytes=" + td.getDownloadedBytes() + ", error=" + td.getDownloadError() + ", pct=" +
+                td.getDownloadPercent());
+
+        switch (status) {
+        case ABORTED:
+        case NOT_STARTED:
+        case UNRECOVERABLE_ERROR:
+            // TODO
+            dj.cleanup();
+            break;
+        case UNKNOWN:
+            return;
+        case IN_PROGRESS:
+            s_logger.info("Resuming jobId: " + jobId + ", status=" + status);
+            td.setResume(true);
+            threadPool.execute(td);
+            break;
+        case RECOVERABLE_ERROR:
+            threadPool.execute(td);
+            break;
+        case DOWNLOAD_FINISHED:
+            if (!(td instanceof S3TemplateDownloader)) {
+                // we currently only create template.properties for NFS by
+                // running some post download script
+                td.setDownloadError("Download success, starting install ");
+                String result = postDownload(jobId);
+                if (result != null) {
+                    s_logger.error("Failed post download script: " + result);
+                    td.setStatus(Status.UNRECOVERABLE_ERROR);
+                    td.setDownloadError("Failed post download script: " + result);
+                } else {
+                    td.setStatus(Status.POST_DOWNLOAD_FINISHED);
+                    td.setDownloadError("Install completed successfully at " + new SimpleDateFormat().format(new Date()));
+                }
+            } else {
+                // for s3 and swift, we skip post download step and just set
+                // status to trigger callback.
+                td.setStatus(Status.POST_DOWNLOAD_FINISHED);
+                // set template size for S3
+                S3TemplateDownloader std = (S3TemplateDownloader)td;
+                long size = std.totalBytes;
+                DownloadJob dnld = jobs.get(jobId);
+                dnld.setTemplatesize(size);
+                dnld.setTemplatePhysicalSize(size);
+                dnld.setTmpltPath(std.getDownloadLocalPath()); // update template path to include file name.
+            }
+            dj.cleanup();
+            break;
+        default:
+            break;
+        }
+    }
+
+    private String computeCheckSum(File f) {
+        byte[] buffer = new byte[8192];
+        int read = 0;
+        MessageDigest digest;
+        String checksum = null;
+        InputStream is = null;
+        try {
+            digest = MessageDigest.getInstance("MD5");
+            is = new FileInputStream(f);
+            while ((read = is.read(buffer)) > 0) {
+                digest.update(buffer, 0, read);
+            }
+            byte[] md5sum = digest.digest();
+            BigInteger bigInt = new BigInteger(1, md5sum);
+            checksum = String.format("%032x", bigInt);
+            return checksum;
+        } catch (IOException e) {
+            return null;
+        } catch (NoSuchAlgorithmException e) {
+            return null;
+        } finally {
+            try {
+                if (is != null)
+                    is.close();
+            } catch (IOException e) {
+                return null;
+            }
+        }
+    }
+
+    /**
+     * Post download activity (install and cleanup). Executed in context of
+     * downloader thread
+     *
+     * @throws IOException
+     */
+    private String postDownload(String jobId) {
+        DownloadJob dnld = jobs.get(jobId);
+        TemplateDownloader td = dnld.getTemplateDownloader();
+        String resourcePath = dnld.getInstallPathPrefix(); // path with mount
+        // directory
+        String finalResourcePath = dnld.getTmpltPath(); // template download
+        // path on secondary
+        // storage
+        ResourceType resourceType = dnld.getResourceType();
+
+        File originalTemplate = new File(td.getDownloadLocalPath());
+        String checkSum = computeCheckSum(originalTemplate);
+        if (checkSum == null) {
+            s_logger.warn("Something wrong happened when try to calculate the checksum of downloaded template!");
+        }
+        dnld.setCheckSum(checkSum);
+
+        int imgSizeGigs = (int)Math.ceil(_storage.getSize(td.getDownloadLocalPath()) * 1.0d / (1024 * 1024 * 1024));
+        imgSizeGigs++; // add one just in case
+        long timeout = imgSizeGigs * installTimeoutPerGig;
+        Script scr = null;
+        String script = resourceType == ResourceType.TEMPLATE ? createTmpltScr : createVolScr;
+        scr = new Script(script, timeout, s_logger);
+        scr.add("-s", Integer.toString(imgSizeGigs));
+        scr.add("-S", Long.toString(td.getMaxTemplateSizeInBytes()));
+        if (dnld.getDescription() != null && dnld.getDescription().length() > 1) {
+            scr.add("-d", dnld.getDescription());
+        }
+        if (dnld.isHvm()) {
+            scr.add("-h");
+        }
+
+        // add options common to ISO and template
+        String extension = dnld.getFormat().getFileExtension();
+        String templateName = "";
+        if (extension.equals("iso")) {
+            templateName = jobs.get(jobId).getTmpltName().trim().replace(" ", "_");
+        } else {
+            templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes()).toString();
+        }
+
+        // run script to mv the temporary template file to the final template
+        // file
+        String templateFilename = templateName + "." + extension;
+        dnld.setTmpltPath(finalResourcePath + "/" + templateFilename);
+        scr.add("-n", templateFilename);
+
+        scr.add("-t", resourcePath);
+        scr.add("-f", td.getDownloadLocalPath()); // this is the temporary
+        // template file downloaded
+        if (dnld.getChecksum() != null && dnld.getChecksum().length() > 1) {
+            scr.add("-c", dnld.getChecksum());
+        }
+        scr.add("-u"); // cleanup
+        String result;
+        result = scr.execute();
+
+        if (result != null) {
+            return result;
+        }
+
+        // Set permissions for the downloaded template
+        File downloadedTemplate = new File(resourcePath + "/" + templateFilename);
+        _storage.setWorldReadableAndWriteable(downloadedTemplate);
+
+        // Set permissions for template/volume.properties
+        String propertiesFile = resourcePath;
+        if (resourceType == ResourceType.TEMPLATE) {
+            propertiesFile += "/template.properties";
+        } else {
+            propertiesFile += "/volume.properties";
+        }
+        File templateProperties = new File(propertiesFile);
+        _storage.setWorldReadableAndWriteable(templateProperties);
+
+        TemplateLocation loc = new TemplateLocation(_storage, resourcePath);
+        try {
+            loc.create(dnld.getId(), true, dnld.getTmpltName());
+        } catch (IOException e) {
+            s_logger.warn("Something is wrong with template location " + resourcePath, e);
+            loc.purge();
+            return "Unable to download due to " + e.getMessage();
+        }
+
+        Iterator<Processor> en = _processors.values().iterator();
+        while (en.hasNext()) {
+            Processor processor = en.next();
+
+            FormatInfo info = null;
+            try {
+                info = processor.process(resourcePath, null, templateName);
+            } catch (InternalErrorException e) {
+                s_logger.error("Template process exception ", e);
+                return e.toString();
+            }
+            if (info != null) {
+                loc.addFormat(info);
+                dnld.setTemplatesize(info.virtualSize);
+                dnld.setTemplatePhysicalSize(info.size);
+                break;
+            }
+        }
+
+        if (!loc.save()) {
+            s_logger.warn("Cleaning up because we're unable to save the formats");
+            loc.purge();
+        }
+
+        return null;
+    }
+
+    @Override
+    public Status getDownloadStatus(String jobId) {
+        DownloadJob job = jobs.get(jobId);
+        if (job != null) {
+            TemplateDownloader td = job.getTemplateDownloader();
+            if (td != null) {
+                return td.getStatus();
+            }
+        }
+        return Status.UNKNOWN;
+    }
+
+    @Override
+    public String downloadS3Template(S3TO s3, long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+            String installPathPrefix, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType) {
+        UUID uuid = UUID.randomUUID();
+        String jobId = uuid.toString();
+
+        URI uri;
+        try {
+            uri = new URI(url);
+        } catch (URISyntaxException e) {
+            throw new CloudRuntimeException("URI is incorrect: " + url);
+        }
+        TemplateDownloader td;
+        if ((uri != null) && (uri.getScheme() != null)) {
+            if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) {
+                td = new S3TemplateDownloader(s3, url, installPathPrefix, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType);
+            } else {
+                throw new CloudRuntimeException("Scheme is not supported " + url);
+            }
+        } else {
+            throw new CloudRuntimeException("Unable to download from URL: " + url);
+        }
+        DownloadJob dj = new DownloadJob(td, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix, resourceType);
+        dj.setTmpltPath(installPathPrefix);
+        jobs.put(jobId, dj);
+        threadPool.execute(td);
+
+        return jobId;
+    }
+
+    @Override
+    public String downloadPublicTemplate(long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
+            String installPathPrefix, String templatePath, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType) {
+        UUID uuid = UUID.randomUUID();
+        String jobId = uuid.toString();
+        String tmpDir = installPathPrefix;
+
+        try {
+
+            if (!_storage.mkdirs(tmpDir)) {
+                s_logger.warn("Unable to create " + tmpDir);
+                return "Unable to create " + tmpDir;
+            }
+            // TO DO - define constant for volume properties.
+            File file =
+                    ResourceType.TEMPLATE == resourceType ? _storage.getFile(tmpDir + File.separator + TemplateLocation.Filename) : _storage.getFile(tmpDir + File.separator +
+                            "volume.properties");
+                    if (file.exists()) {
+                        file.delete();
+                    }
+
+                    if (!file.createNewFile()) {
+                        s_logger.warn("Unable to create new file: " + file.getAbsolutePath());
+                        return "Unable to create new file: " + file.getAbsolutePath();
+                    }
+
+                    URI uri;
+                    try {
+                        uri = new URI(url);
+                    } catch (URISyntaxException e) {
+                        throw new CloudRuntimeException("URI is incorrect: " + url);
+                    }
+                    TemplateDownloader td;
+                    if ((uri != null) && (uri.getScheme() != null)) {
+                        if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) {
+                            td = new HttpTemplateDownloader(_storage, url, tmpDir, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType);
+                        } else if (uri.getScheme().equalsIgnoreCase("file")) {
+                            td = new LocalTemplateDownloader(_storage, url, tmpDir, maxTemplateSizeInBytes, new Completion(jobId));
+                        } else if (uri.getScheme().equalsIgnoreCase("scp")) {
+                            td = new ScpTemplateDownloader(_storage, url, tmpDir, maxTemplateSizeInBytes, new Completion(jobId));
+                        } else if (uri.getScheme().equalsIgnoreCase("nfs") || uri.getScheme().equalsIgnoreCase("cifs")) {
+                            td = null;
+                            // TODO: implement this.
+                            throw new CloudRuntimeException("Scheme is not supported " + url);
+                        } else {
+                            throw new CloudRuntimeException("Scheme is not supported " + url);
+                        }
+                    } else {
+                        throw new CloudRuntimeException("Unable to download from URL: " + url);
+                    }
+                    // NOTE the difference between installPathPrefix and templatePath
+                    // here. instalPathPrefix is the absolute path for template
+                    // including mount directory
+                    // on ssvm, while templatePath is the final relative path on
+                    // secondary storage.
+                    DownloadJob dj = new DownloadJob(td, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix, resourceType);
+                    dj.setTmpltPath(templatePath);
+                    jobs.put(jobId, dj);
+                    threadPool.execute(td);
+
+                    return jobId;
+        } catch (IOException e) {
+            s_logger.warn("Unable to download to " + tmpDir, e);
+            return null;
+        }
+    }
+
+    @Override
+    public String getDownloadError(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTemplateDownloader().getDownloadError();
+        }
+        return null;
+    }
+
+    public long getDownloadTemplateSize(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTemplatesize();
+        }
+        return 0;
+    }
+
+    public String getDownloadCheckSum(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getChecksum();
+        }
+        return null;
+    }
+
+    public long getDownloadTemplatePhysicalSize(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTemplatePhysicalSize();
+        }
+        return 0;
+    }
+
+    // @Override
+    public String getDownloadLocalPath(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTemplateDownloader().getDownloadLocalPath();
+        }
+        return null;
+    }
+
+    @Override
+    public int getDownloadPct(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTemplateDownloader().getDownloadPercent();
+        }
+        return 0;
+    }
+
+    public static VMTemplateHostVO.Status convertStatus(Status tds) {
+        switch (tds) {
+        case ABORTED:
+            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
+        case DOWNLOAD_FINISHED:
+            return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS;
+        case IN_PROGRESS:
+            return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS;
+        case NOT_STARTED:
+            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
+        case RECOVERABLE_ERROR:
+            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
+        case UNKNOWN:
+            return VMTemplateHostVO.Status.UNKNOWN;
+        case UNRECOVERABLE_ERROR:
+            return VMTemplateHostVO.Status.DOWNLOAD_ERROR;
+        case POST_DOWNLOAD_FINISHED:
+            return VMTemplateHostVO.Status.DOWNLOADED;
+        default:
+            return VMTemplateHostVO.Status.UNKNOWN;
+        }
+    }
+
+    @Override
+    public com.cloud.storage.VMTemplateHostVO.Status getDownloadStatus2(String jobId) {
+        return convertStatus(getDownloadStatus(jobId));
+    }
+
+    @Override
+    public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd) {
+        ResourceType resourceType = cmd.getResourceType();
+        if (cmd instanceof DownloadProgressCommand) {
+            return handleDownloadProgressCmd(resource, (DownloadProgressCommand)cmd);
+        }
+
+        if (cmd.getUrl() == null) {
+            return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download",
+                    VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
+        }
+
+        if (cmd.getName() == null) {
+            return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
+        }
+
+        DataStoreTO dstore = cmd.getDataStore();
+        String installPathPrefix = cmd.getInstallPath();
+        // for NFS, we need to get mounted path
+        if (dstore instanceof NfsTO) {
+            installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl()) + File.separator + installPathPrefix;
+        }
+        String user = null;
+        String password = null;
+        if (cmd.getAuth() != null) {
+            user = cmd.getAuth().getUserName();
+            password = cmd.getAuth().getPassword();
+        }
+        // TO DO - Define Volume max size as well
+        long maxDownloadSizeInBytes =
+                (cmd.getMaxDownloadSizeInBytes() == null) ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : (cmd.getMaxDownloadSizeInBytes());
+        String jobId = null;
+        if (dstore instanceof S3TO) {
+            jobId =
+                    downloadS3Template((S3TO)dstore, cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(),
+                            cmd.getChecksum(), installPathPrefix, user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
+        } else {
+            jobId =
+                    downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(),
+                            cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
+        }
+        sleep();
+        if (jobId == null) {
+            return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
+        }
+        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
+                getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
+    }
+
+    private void sleep() {
+        try {
+            Thread.sleep(3000);
+        } catch (InterruptedException e) {
+            // ignore
+        }
+    }
+
+    private DownloadAnswer handleDownloadProgressCmd(SecondaryStorageResource resource, DownloadProgressCommand cmd) {
+        String jobId = cmd.getJobId();
+        DownloadAnswer answer;
+        DownloadJob dj = null;
+        if (jobId != null) {
+            dj = jobs.get(jobId);
+        }
+        if (dj == null) {
+            if (cmd.getRequest() == RequestType.GET_OR_RESTART) {
+                DownloadCommand dcmd = new DownloadCommand(cmd);
+                return handleDownloadCommand(resource, dcmd);
+            } else {
+                return new DownloadAnswer("Cannot find job", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.UNKNOWN);
+            }
+        }
+        TemplateDownloader td = dj.getTemplateDownloader();
+        switch (cmd.getRequest()) {
+        case GET_STATUS:
+            break;
+        case ABORT:
+            td.stopDownload();
+            sleep();
+            break;
+        case RESTART:
+            td.stopDownload();
+            sleep();
+            threadPool.execute(td);
+            break;
+        case PURGE:
+            td.stopDownload();
+            answer =
+                    new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId),
+                            getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
+            jobs.remove(jobId);
+            return answer;
+        default:
+            break; // TODO
+        }
+        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
+                getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
+    }
+
+    private String getInstallPath(String jobId) {
+        DownloadJob dj = jobs.get(jobId);
+        if (dj != null) {
+            return dj.getTmpltPath();
+        }
+        return null;
+    }
+
+    private List<String> listVolumes(String rootdir) {
+        List<String> result = new ArrayList<String>();
+
+        Script script = new Script(listVolScr, s_logger);
+        script.add("-r", rootdir);
+        ZfsPathParser zpp = new ZfsPathParser(rootdir);
+        script.execute(zpp);
+        result.addAll(zpp.getPaths());
+        s_logger.info("found " + zpp.getPaths().size() + " volumes" + zpp.getPaths());
+        return result;
+    }
+
+    private List<String> listTemplates(String rootdir) {
+        List<String> result = new ArrayList<String>();
+
+        Script script = new Script(listTmpltScr, s_logger);
+        script.add("-r", rootdir);
+        ZfsPathParser zpp = new ZfsPathParser(rootdir);
+        script.execute(zpp);
+        result.addAll(zpp.getPaths());
+        s_logger.info("found " + zpp.getPaths().size() + " templates" + zpp.getPaths());
+        return result;
+    }
+
+    @Override
+    public Map<String, TemplateProp> gatherTemplateInfo(String rootDir) {
+        Map<String, TemplateProp> result = new HashMap<String, TemplateProp>();
+        String templateDir = rootDir + File.separator + _templateDir;
+
+        if (!_storage.exists(templateDir)) {
+            _storage.mkdirs(templateDir);
+        }
+
+        List<String> publicTmplts = listTemplates(templateDir);
+        for (String tmplt : publicTmplts) {
+            String path = tmplt.substring(0, tmplt.lastIndexOf(File.separator));
+            TemplateLocation loc = new TemplateLocation(_storage, path);
+            try {
+                if (!loc.load()) {
+                    s_logger.warn("Post download installation was not completed for " + path);
+                    // loc.purge();
+                    _storage.cleanup(path, templateDir);
+                    continue;
+                }
+            } catch (IOException e) {
+                s_logger.warn("Unable to load template location " + path, e);
+                continue;
+            }
+
+            TemplateProp tInfo = loc.getTemplateInfo();
+
+            if ((tInfo.getSize() == tInfo.getPhysicalSize()) && (tInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
+                try {
+                    Processor processor = _processors.get("OVA Processor");
+                    OVAProcessor vmdkProcessor = (OVAProcessor)processor;
+                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1));
+                    tInfo.setSize(vSize);
+                    loc.updateVirtualSize(vSize);
+                    loc.save();
+                } catch (Exception e) {
+                    s_logger.error("Unable to get the virtual size of the template: " + tInfo.getInstallPath() + " due to " + e.getMessage());
+                }
+            }
+
+            result.put(tInfo.getTemplateName(), tInfo);
+            s_logger.debug("Added template name: " + tInfo.getTemplateName() + ", path: " + tmplt);
+        }
+        /*
+        for (String tmplt : isoTmplts) {
+            String tmp[];
+            tmp = tmplt.split("/");
+            String tmpltName = tmp[tmp.length - 2];
+            tmplt = tmplt.substring(tmplt.lastIndexOf("iso/"));
+            TemplateInfo tInfo = new TemplateInfo(tmpltName, tmplt, false);
+            s_logger.debug("Added iso template name: " + tmpltName + ", path: " + tmplt);
+            result.put(tmpltName, tInfo);
+        }
+         */
+        return result;
+    }
+
+    @Override
+    public Map<Long, TemplateProp> gatherVolumeInfo(String rootDir) {
+        Map<Long, TemplateProp> result = new HashMap<Long, TemplateProp>();
+        String volumeDir = rootDir + File.separator + _volumeDir;
+
+        if (!_storage.exists(volumeDir)) {
+            _storage.mkdirs(volumeDir);
+        }
+
+        List<String> vols = listVolumes(volumeDir);
+        for (String vol : vols) {
+            String path = vol.substring(0, vol.lastIndexOf(File.separator));
+            TemplateLocation loc = new TemplateLocation(_storage, path);
+            try {
+                if (!loc.load()) {
+                    s_logger.warn("Post download installation was not completed for " + path);
+                    // loc.purge();
+                    _storage.cleanup(path, volumeDir);
+                    continue;
+                }
+            } catch (IOException e) {
+                s_logger.warn("Unable to load volume location " + path, e);
+                continue;
+            }
+
+            TemplateProp vInfo = loc.getTemplateInfo();
+
+            if ((vInfo.getSize() == vInfo.getPhysicalSize()) && (vInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
+                try {
+                    Processor processor = _processors.get("OVA Processor");
+                    OVAProcessor vmdkProcessor = (OVAProcessor)processor;
+                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.getInstallPath().substring(vInfo.getInstallPath().lastIndexOf(File.separator) + 1));
+                    vInfo.setSize(vSize);
+                    loc.updateVirtualSize(vSize);
+                    loc.save();
+                } catch (Exception e) {
+                    s_logger.error("Unable to get the virtual size of the volume: " + vInfo.getInstallPath() + " due to " + e.getMessage());
+                }
+            }
+
+            result.put(vInfo.getId(), vInfo);
+            s_logger.debug("Added volume name: " + vInfo.getTemplateName() + ", path: " + vol);
+        }
+        return result;
+    }
+
+    public static class ZfsPathParser extends OutputInterpreter {
+        String _parent;
+        List<String> paths = new ArrayList<String>();
+
+        public ZfsPathParser(String parent) {
+            _parent = parent;
+        }
+
+        @Override
+        public String interpret(BufferedReader reader) throws IOException {
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                paths.add(line);
+            }
+            return null;
+        }
+
+        public List<String> getPaths() {
+            return paths;
+        }
+
+        @Override
+        public boolean drain() {
+            return true;
+        }
+    }
+
+    public DownloadManagerImpl() {
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        _name = name;
+
+        String value = null;
+
+        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
+        if (_storage == null) {
+            value = (String)params.get(StorageLayer.ClassConfigKey);
+            if (value == null) {
+                throw new ConfigurationException("Unable to find the storage layer");
+            }
+
+            Class<StorageLayer> clazz;
+            try {
+                clazz = (Class<StorageLayer>)Class.forName(value);
+                _storage = clazz.newInstance();
+            } catch (ClassNotFoundException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (InstantiationException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (IllegalAccessException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            }
+        }
+
+        String inSystemVM = (String)params.get("secondary.storage.vm");
+        if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
+            s_logger.info("DownloadManager: starting additional services since we are inside system vm");
+            startAdditionalServices();
+            blockOutgoingOnPrivate();
+        }
+
+        value = (String)params.get("install.timeout.pergig");
+        installTimeoutPerGig = NumbersUtil.parseInt(value, 15 * 60) * 1000;
+
+        value = (String)params.get("install.numthreads");
+        final int numInstallThreads = NumbersUtil.parseInt(value, 10);
+
+        String scriptsDir = (String)params.get("template.scripts.dir");
+        if (scriptsDir == null) {
+            scriptsDir = "scripts/storage/secondary";
+        }
+
+        listTmpltScr = Script.findScript(scriptsDir, "listvmtmplt.sh");
+        if (listTmpltScr == null) {
+            throw new ConfigurationException("Unable to find the listvmtmplt.sh");
+        }
+        s_logger.info("listvmtmplt.sh found in " + listTmpltScr);
+
+        createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
+        if (createTmpltScr == null) {
+            throw new ConfigurationException("Unable to find createtmplt.sh");
+        }
+        s_logger.info("createtmplt.sh found in " + createTmpltScr);
+
+        listVolScr = Script.findScript(scriptsDir, "listvolume.sh");
+        if (listVolScr == null) {
+            throw new ConfigurationException("Unable to find the listvolume.sh");
+        }
+        s_logger.info("listvolume.sh found in " + listVolScr);
+
+        createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
+        if (createVolScr == null) {
+            throw new ConfigurationException("Unable to find createvolume.sh");
+        }
+        s_logger.info("createvolume.sh found in " + createVolScr);
+
+        _processors = new HashMap<String, Processor>();
+
+        Processor processor = new VhdProcessor();
+        processor.configure("VHD Processor", params);
+        _processors.put("VHD Processor", processor);
+
+        processor = new IsoProcessor();
+        processor.configure("ISO Processor", params);
+        _processors.put("ISO Processor", processor);
+
+        processor = new QCOW2Processor();
+        processor.configure("QCOW2 Processor", params);
+        _processors.put("QCOW2 Processor", processor);
+
+        processor = new OVAProcessor();
+        processor.configure("OVA Processor", params);
+        _processors.put("OVA Processor", processor);
+
+        processor = new VmdkProcessor();
+        processor.configure("VMDK Processor", params);
+        _processors.put("VMDK Processor", processor);
+
+        processor = new RawImageProcessor();
+        processor.configure("Raw Image Processor", params);
+        _processors.put("Raw Image Processor", processor);
+
+        _templateDir = (String)params.get("public.templates.root.dir");
+        if (_templateDir == null) {
+            _templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;
+        }
+        _templateDir += File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
+        _volumeDir = TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + File.separator;
+        // Add more processors here.
+        threadPool = Executors.newFixedThreadPool(numInstallThreads);
+        return true;
+    }
+
+    private void blockOutgoingOnPrivate() {
+        Script command = new Script("/bin/bash", s_logger);
+        String intf = "eth1";
+        command.add("-c");
+        command.add("iptables -A OUTPUT -o " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "80" + " -j REJECT;" + "iptables -A OUTPUT -o " + intf +
+                " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j REJECT;");
+
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in blocking outgoing to port 80/443 err=" + result);
+            return;
+        }
+    }
+
+    @Override
+    public String getName() {
+        return _name;
+    }
+
+    @Override
+    public boolean start() {
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        return true;
+    }
+
+    private void startAdditionalServices() {
+
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("if [ -d /etc/apache2 ] ; then service apache2 stop; else service httpd stop; fi ");
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in stopping httpd service err=" + result);
+        }
+        String port = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
+        String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
+
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j ACCEPT;" + "iptables -I INPUT -i " + intf +
+                " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j ACCEPT;");
+
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in opening up httpd port err=" + result);
+            return;
+        }
+
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in starting httpd service err=" + result);
+            return;
+        }
+        command = new Script("mkdir", s_logger);
+        command.add("-p");
+        command.add("/var/www/html/copy/template");
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in creating directory =" + result);
+            return;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManager.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManager.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManager.java
new file mode 100755
index 0000000..be99fea
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManager.java
@@ -0,0 +1,82 @@
+// 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.storage.template;
+
+import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
+
+import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
+import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
+import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.UploadAnswer;
+import com.cloud.agent.api.storage.UploadCommand;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.Upload.Status;
+import com.cloud.storage.template.TemplateUploader;
+import com.cloud.utils.component.Manager;
+
+public interface UploadManager extends Manager {
+
+    /**
+     * @param jobId job Id
+     * @return status of the upload job
+     */
+    public TemplateUploader.Status getUploadStatus(String jobId);
+
+    /**
+     * @param jobId job Id
+     * @return status of the upload job
+     */
+    public Status getUploadStatus2(String jobId);
+
+    /**
+     * Get the upload percent of a upload job
+     * @param jobId job Id
+     * @return
+     */
+    public int getUploadPct(String jobId);
+
+    /**
+     * Get the upload error if any
+     * @param jobId job Id
+     * @return
+     */
+    public String getUploadError(String jobId);
+
+    /**
+     * Get the local path for the upload
+     * @param jobId job Id
+     * @return
+    public String getUploadLocalPath(String jobId);
+     */
+
+    /** Handle upload commands from the management server
+     * @param cmd cmd from server
+     * @return answer representing status of upload.
+     */
+    public UploadAnswer handleUploadCommand(SecondaryStorageResource resource, UploadCommand cmd);
+
+    public String getPublicTemplateRepo();
+
+    String uploadPublicTemplate(long id, String url, String name, ImageFormat format, Long accountId, String descr, String cksum, String installPathPrefix, String user,
+        String password, long maxTemplateSizeInBytes);
+
+    CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd);
+
+    DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd);
+
+}


[24/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fixed agent code to handle untagged public vlan while parsing the vlan id


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7f780f26
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7f780f26
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7f780f26

Branch: refs/heads/rbac
Commit: 7f780f26f99aa063147c38b208eaf191ce8ccac3
Parents: adf6026
Author: Rajesh Battala <ra...@citrix.com>
Authored: Wed Feb 5 23:44:14 2014 +0530
Committer: Rajesh Battala <ra...@citrix.com>
Committed: Wed Feb 5 23:44:14 2014 +0530

----------------------------------------------------------------------
 .../DotNet/ServerResource/HypervResource/WmiCallsV2.cs       | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f780f26/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs
index b9694f0..dde6e21 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs
@@ -391,7 +391,7 @@ namespace HypervResource
                     string vlan = null;
                     string isolationUri = nic.isolationUri;
                     string broadcastUri = nic.broadcastUri;
-                    if ( (broadcastUri != null ) || (isolationUri != null && isolationUri.StartsWith("vlan://")) && !isolationUri.Equals("vlan://untagged"))
+                    if ( (broadcastUri != null ) || (isolationUri != null && isolationUri.StartsWith("vlan://")))
                     {
                         if (broadcastUri != null && broadcastUri.StartsWith("storage"))
                         {
@@ -402,7 +402,11 @@ namespace HypervResource
                             vlan = isolationUri.Substring("vlan://".Length);
                         }
                         int tmp;
-                        if (!int.TryParse(vlan, out tmp))
+                        if (vlan.Equals("untagged", StringComparison.CurrentCultureIgnoreCase) ) {
+                            // recevied vlan is untagged, don't parse for the vlan in the isolation uri
+                            vlan = null;
+                        }
+                        else if (!int.TryParse(vlan, out tmp))
                         {
                             // TODO: double check exception type
                             errMsg = string.Format("Invalid VLAN value {0} for on vm {1} for nic uuid {2}", isolationUri, vmName, nic.uuid);


[02/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java b/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
deleted file mode 100755
index cdbc52d..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
+++ /dev/null
@@ -1,550 +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.storage.template;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
-
-import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
-import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
-import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.UploadAnswer;
-import com.cloud.agent.api.storage.UploadCommand;
-import com.cloud.agent.api.storage.UploadProgressCommand;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.StorageLayer;
-import com.cloud.storage.Upload;
-import com.cloud.storage.UploadVO;
-import com.cloud.storage.template.FtpTemplateUploader;
-import com.cloud.storage.template.TemplateUploader;
-import com.cloud.storage.template.TemplateUploader.Status;
-import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
-
-public class UploadManagerImpl extends ManagerBase implements UploadManager {
-
-    public class Completion implements UploadCompleteCallback {
-        private final String jobId;
-
-        public Completion(String jobId) {
-            this.jobId = jobId;
-        }
-
-        @Override
-        public void uploadComplete(Status status) {
-            setUploadStatus(jobId, status);
-        }
-    }
-
-    private static class UploadJob {
-        private final TemplateUploader tu;
-
-        public UploadJob(TemplateUploader tu, String jobId, long id, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-                String installPathPrefix) {
-            super();
-            this.tu = tu;
-        }
-
-        public TemplateUploader getTemplateUploader() {
-            return tu;
-        }
-
-        public void cleanup() {
-            if (tu != null) {
-                String upldPath = tu.getUploadLocalPath();
-                if (upldPath != null) {
-                    File f = new File(upldPath);
-                    f.delete();
-                }
-            }
-        }
-
-    }
-
-    public static final Logger s_logger = Logger.getLogger(UploadManagerImpl.class);
-    private ExecutorService threadPool;
-    private final Map<String, UploadJob> jobs = new ConcurrentHashMap<String, UploadJob>();
-    private String parentDir;
-    private final String extractMountPoint = "/mnt/SecStorage/extractmnt";
-    private StorageLayer _storage;
-    private boolean hvm;
-
-    @Override
-    public String uploadPublicTemplate(long id, String url, String name, ImageFormat format, Long accountId, String descr, String cksum, String installPathPrefix,
-            String userName, String passwd, long templateSizeInBytes) {
-
-        UUID uuid = UUID.randomUUID();
-        String jobId = uuid.toString();
-
-        String completePath = parentDir + File.separator + installPathPrefix;
-        s_logger.debug("Starting upload from " + completePath);
-
-        URI uri;
-        try {
-            uri = new URI(url);
-        } catch (URISyntaxException e) {
-            s_logger.error("URI is incorrect: " + url);
-            throw new CloudRuntimeException("URI is incorrect: " + url);
-        }
-        TemplateUploader tu;
-        if ((uri != null) && (uri.getScheme() != null)) {
-            if (uri.getScheme().equalsIgnoreCase("ftp")) {
-                tu = new FtpTemplateUploader(completePath, url, new Completion(jobId), templateSizeInBytes);
-            } else {
-                s_logger.error("Scheme is not supported " + url);
-                throw new CloudRuntimeException("Scheme is not supported " + url);
-            }
-        } else {
-            s_logger.error("Unable to download from URL: " + url);
-            throw new CloudRuntimeException("Unable to download from URL: " + url);
-        }
-        UploadJob uj = new UploadJob(tu, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix);
-        jobs.put(jobId, uj);
-        threadPool.execute(tu);
-
-        return jobId;
-
-    }
-
-    @Override
-    public String getUploadError(String jobId) {
-        UploadJob uj = jobs.get(jobId);
-        if (uj != null) {
-            return uj.getTemplateUploader().getUploadError();
-        }
-        return null;
-    }
-
-    @Override
-    public int getUploadPct(String jobId) {
-        UploadJob uj = jobs.get(jobId);
-        if (uj != null) {
-            return uj.getTemplateUploader().getUploadPercent();
-        }
-        return 0;
-    }
-
-    @Override
-    public Status getUploadStatus(String jobId) {
-        UploadJob job = jobs.get(jobId);
-        if (job != null) {
-            TemplateUploader tu = job.getTemplateUploader();
-            if (tu != null) {
-                return tu.getStatus();
-            }
-        }
-        return Status.UNKNOWN;
-    }
-
-    public static UploadVO.Status convertStatus(Status tds) {
-        switch (tds) {
-        case ABORTED:
-            return UploadVO.Status.NOT_UPLOADED;
-        case UPLOAD_FINISHED:
-            return UploadVO.Status.UPLOAD_IN_PROGRESS;
-        case IN_PROGRESS:
-            return UploadVO.Status.UPLOAD_IN_PROGRESS;
-        case NOT_STARTED:
-            return UploadVO.Status.NOT_UPLOADED;
-        case RECOVERABLE_ERROR:
-            return UploadVO.Status.NOT_UPLOADED;
-        case UNKNOWN:
-            return UploadVO.Status.UNKNOWN;
-        case UNRECOVERABLE_ERROR:
-            return UploadVO.Status.UPLOAD_ERROR;
-        case POST_UPLOAD_FINISHED:
-            return UploadVO.Status.UPLOADED;
-        default:
-            return UploadVO.Status.UNKNOWN;
-        }
-    }
-
-    @Override
-    public com.cloud.storage.UploadVO.Status getUploadStatus2(String jobId) {
-        return convertStatus(getUploadStatus(jobId));
-    }
-
-    @Override
-    public String getPublicTemplateRepo() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    private UploadAnswer handleUploadProgressCmd(UploadProgressCommand cmd) {
-        String jobId = cmd.getJobId();
-        UploadAnswer answer;
-        UploadJob uj = null;
-        if (jobId != null)
-            uj = jobs.get(jobId);
-        if (uj == null) {
-            return new UploadAnswer(null, 0, "Cannot find job", com.cloud.storage.UploadVO.Status.UNKNOWN, "", "", 0);
-        }
-        TemplateUploader td = uj.getTemplateUploader();
-        switch (cmd.getRequest()) {
-        case GET_STATUS:
-            break;
-        case ABORT:
-            td.stopUpload();
-            sleep();
-            break;
-            /*case RESTART:
-            td.stopUpload();
-            sleep();
-            threadPool.execute(td);
-            break;*/
-        case PURGE:
-            td.stopUpload();
-            answer =
-                    new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
-                            getUploadTemplateSize(jobId));
-            jobs.remove(jobId);
-            return answer;
-        default:
-            break; // TODO
-        }
-        return new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
-                getUploadTemplateSize(jobId));
-    }
-
-    @Override
-    public UploadAnswer handleUploadCommand(SecondaryStorageResource resource, UploadCommand cmd) {
-        s_logger.warn("Handling the upload " + cmd.getInstallPath() + " " + cmd.getId());
-        if (cmd instanceof UploadProgressCommand) {
-            return handleUploadProgressCmd((UploadProgressCommand)cmd);
-        }
-
-        String user = null;
-        String password = null;
-        String jobId =
-                uploadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(),
-                        cmd.getInstallPath(), user, password, cmd.getTemplateSizeInBytes());
-        sleep();
-        return new UploadAnswer(jobId, getUploadPct(jobId), getUploadError(jobId), getUploadStatus2(jobId), getUploadLocalPath(jobId), getInstallPath(jobId),
-                getUploadTemplateSize(jobId));
-    }
-
-    @Override
-    public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd) {
-
-        boolean isApacheUp = checkAndStartApache();
-        if (!isApacheUp) {
-            String errorString = "Error in starting Apache server ";
-            s_logger.error(errorString);
-            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-        // Create the directory structure so that its visible under apache server root
-        String extractDir = "/var/www/html/userdata/";
-        Script command = new Script("mkdir", s_logger);
-        command.add("-p");
-        command.add(extractDir);
-        String result = command.execute();
-        if (result != null) {
-            String errorString = "Error in creating directory =" + result;
-            s_logger.error(errorString);
-            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-
-        // Create a random file under the directory for security reasons.
-        String uuid = cmd.getExtractLinkUUID();
-        command = new Script("touch", s_logger);
-        command.add(extractDir + uuid);
-        result = command.execute();
-        if (result != null) {
-            String errorString = "Error in creating file " + uuid + " ,error: " + result;
-            s_logger.warn(errorString);
-            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-
-        // Create a symbolic link from the actual directory to the template location. The entity would be directly visible under /var/www/html/userdata/cmd.getInstallPath();
-        command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("ln -sf /mnt/SecStorage/" + cmd.getParent() + File.separator + cmd.getInstallPath() + " " + extractDir + uuid);
-        result = command.execute();
-        if (result != null) {
-            String errorString = "Error in linking  err=" + result;
-            s_logger.error(errorString);
-            return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-
-        return new CreateEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
-
-    }
-
-    @Override
-    public DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd) {
-
-        //Delete the soft link. Example path = volumes/8/74eeb2c6-8ab1-4357-841f-2e9d06d1f360.vhd
-        s_logger.warn("handleDeleteEntityDownloadURLCommand Path:" + cmd.getPath() + " Type:" + cmd.getType().toString());
-        String path = cmd.getPath();
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-
-        //We just need to remove the UUID.vhd
-        String extractUrl = cmd.getExtractUrl();
-        command.add("unlink /var/www/html/userdata/" + extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1));
-        String result = command.execute();
-        if (result != null) {
-            String errorString = "Error in deleting =" + result;
-            s_logger.warn(errorString);
-            return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-
-        // If its a volume also delete the Hard link since it was created only for the purpose of download.
-        if (cmd.getType() == Upload.Type.VOLUME) {
-            command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            command.add("rm -f /mnt/SecStorage/" + cmd.getParentPath() + File.separator + path);
-            s_logger.warn(" " + parentDir + File.separator + path);
-            result = command.execute();
-            if (result != null) {
-                String errorString = "Error in linking  err=" + result;
-                s_logger.warn(errorString);
-                return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-            }
-        }
-
-        return new DeleteEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
-    }
-
-    private String getInstallPath(String jobId) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    private String getUploadLocalPath(String jobId) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    private long getUploadTemplateSize(String jobId) {
-        return 0;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-
-        String value = null;
-
-        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
-        if (_storage == null) {
-            value = (String)params.get(StorageLayer.ClassConfigKey);
-            if (value == null) {
-                throw new ConfigurationException("Unable to find the storage layer");
-            }
-
-            Class<StorageLayer> clazz;
-            try {
-                clazz = (Class<StorageLayer>)Class.forName(value);
-                _storage = clazz.newInstance();
-            } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            } catch (InstantiationException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            } catch (IllegalAccessException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            }
-        }
-
-        String inSystemVM = (String)params.get("secondary.storage.vm");
-        if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
-            s_logger.info("UploadManager: starting additional services since we are inside system vm");
-            startAdditionalServices();
-            //blockOutgoingOnPrivate();
-        }
-
-        value = (String)params.get("install.numthreads");
-        final int numInstallThreads = NumbersUtil.parseInt(value, 10);
-
-        String scriptsDir = (String)params.get("template.scripts.dir");
-        if (scriptsDir == null) {
-            scriptsDir = "scripts/storage/secondary";
-        }
-
-        // Add more processors here.
-        threadPool = Executors.newFixedThreadPool(numInstallThreads);
-
-        return true;
-    }
-
-    private void startAdditionalServices() {
-
-        Script command = new Script("rm", s_logger);
-        command.add("-rf");
-        command.add(extractMountPoint);
-        String result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in creating file " + extractMountPoint + " ,error: " + result);
-            return;
-        }
-
-        command = new Script("touch", s_logger);
-        command.add(extractMountPoint);
-        result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in creating file " + extractMountPoint + " ,error: " + result);
-            return;
-        }
-
-        command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("ln -sf " + parentDir + " " + extractMountPoint);
-        result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in linking  err=" + result);
-            return;
-        }
-
-    }
-
-    /**
-     * Get notified of change of job status. Executed in context of uploader thread
-     *
-     * @param jobId
-     *            the id of the job
-     * @param status
-     *            the status of the job
-     */
-    public void setUploadStatus(String jobId, Status status) {
-        UploadJob uj = jobs.get(jobId);
-        if (uj == null) {
-            s_logger.warn("setUploadStatus for jobId: " + jobId + ", status=" + status + " no job found");
-            return;
-        }
-        TemplateUploader tu = uj.getTemplateUploader();
-        s_logger.warn("Upload Completion for jobId: " + jobId + ", status=" + status);
-        s_logger.warn("UploadedBytes=" + tu.getUploadedBytes() + ", error=" + tu.getUploadError() + ", pct=" + tu.getUploadPercent());
-
-        switch (status) {
-        case ABORTED:
-        case NOT_STARTED:
-        case UNRECOVERABLE_ERROR:
-            // Delete the entity only if its a volume. TO DO - find a better way of finding it a volume.
-            if (uj.getTemplateUploader().getUploadLocalPath().indexOf("volume") > -1) {
-                uj.cleanup();
-            }
-            break;
-        case UNKNOWN:
-            return;
-        case IN_PROGRESS:
-            s_logger.info("Resuming jobId: " + jobId + ", status=" + status);
-            tu.setResume(true);
-            threadPool.execute(tu);
-            break;
-        case RECOVERABLE_ERROR:
-            threadPool.execute(tu);
-            break;
-        case UPLOAD_FINISHED:
-            tu.setUploadError("Upload success, starting install ");
-            String result = postUpload(jobId);
-            if (result != null) {
-                s_logger.error("Failed post upload script: " + result);
-                tu.setStatus(Status.UNRECOVERABLE_ERROR);
-                tu.setUploadError("Failed post upload script: " + result);
-            } else {
-                s_logger.warn("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
-                tu.setStatus(Status.POST_UPLOAD_FINISHED);
-                tu.setUploadError("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
-            }
-            // Delete the entity only if its a volume. TO DO - find a better way of finding it a volume.
-            if (uj.getTemplateUploader().getUploadLocalPath().indexOf("volume") > -1) {
-                uj.cleanup();
-            }
-            break;
-        default:
-            break;
-        }
-    }
-
-    private String postUpload(String jobId) {
-        return null;
-    }
-
-    private void sleep() {
-        try {
-            Thread.sleep(3000);
-        } catch (InterruptedException e) {
-            // ignore
-        }
-    }
-
-    private boolean checkAndStartApache() {
-
-        //Check whether the Apache server is running
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 status | grep pid; else service httpd status | grep pid; fi ");
-        String result = command.execute();
-
-        //Apache Server is not running. Try to start it.
-        if (result != null) {
-
-            /*s_logger.warn("Apache server not running, trying to start it");
-            String port = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
-            String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
-
-            command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            command.add("iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j DROP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j HTTP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j DROP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j HTTP;" +
-                        "iptables -F HTTP;" +
-                        "iptables -X HTTP;" +
-                        "iptables -N HTTP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j DROP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j DROP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j HTTP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j HTTP;");
-
-            result = command.execute();
-            if (result != null) {
-                s_logger.warn("Error in opening up httpd port err=" + result );
-                return false;
-            }*/
-
-            command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
-            result = command.execute();
-            if (result != null) {
-                s_logger.warn("Error in starting httpd service err=" + result);
-                return false;
-            }
-        }
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java b/services/secondary-storage/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
deleted file mode 100644
index e0fcbae..0000000
--- a/services/secondary-storage/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java
+++ /dev/null
@@ -1,143 +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.storage.resource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-
-import javax.naming.ConfigurationException;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import org.apache.cloudstack.storage.command.CopyCmdAnswer;
-import org.apache.cloudstack.storage.command.CopyCommand;
-import org.apache.cloudstack.storage.command.DownloadCommand;
-import org.apache.cloudstack.storage.to.TemplateObjectTO;
-
-import com.cloud.agent.api.storage.DownloadAnswer;
-import com.cloud.agent.api.storage.ListTemplateAnswer;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.to.DataObjectType;
-import com.cloud.agent.api.to.NfsTO;
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.storage.DataStoreRole;
-import com.cloud.storage.Storage;
-import com.cloud.utils.PropertiesUtil;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public class LocalNfsSecondaryStorageResourceTest extends TestCase {
-    private static Map<String, Object> testParams;
-
-    private static final Logger s_logger = Logger.getLogger(LocalNfsSecondaryStorageResourceTest.class.getName());
-
-    LocalNfsSecondaryStorageResource resource;
-
-    @Before
-    @Override
-    public void setUp() throws ConfigurationException {
-        resource = new LocalNfsSecondaryStorageResource();
-        resource.setInSystemVM(true);
-
-        testParams = PropertiesUtil.toMap(loadProperties());
-        resource.configureStorageLayerClass(testParams);
-        Object testLocalRoot = testParams.get("testLocalRoot");
-        resource.setParentPath("/mnt");
-
-        if (testLocalRoot != null) {
-            resource.setParentPath((String)testLocalRoot);
-        }
-
-        System.setProperty("paths.script", "/Users/edison/develop/asf-master/script");
-        //resource.configure("test", new HashMap<String, Object>());
-    }
-
-    @Test
-    public void testExecuteRequest() throws Exception {
-        TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
-        NfsTO cacheStore = Mockito.mock(NfsTO.class);
-        Mockito.when(cacheStore.getUrl()).thenReturn("nfs://nfs2.lab.vmops.com/export/home/edison/");
-        SwiftTO swift = Mockito.mock(SwiftTO.class);
-        Mockito.when(swift.getEndPoint()).thenReturn("https://objects.dreamhost.com/auth");
-        Mockito.when(swift.getAccount()).thenReturn("cloudstack");
-        Mockito.when(swift.getUserName()).thenReturn("images");
-        Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u");
-
-        Mockito.when(template.getDataStore()).thenReturn(swift);
-        Mockito.when(template.getPath()).thenReturn("template/1/1/");
-        Mockito.when(template.isRequiresHvm()).thenReturn(true);
-        Mockito.when(template.getId()).thenReturn(1L);
-        Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD);
-        Mockito.when(template.getOrigUrl()).thenReturn("http://nfs1.lab.vmops.com/templates/test.bz2");
-        Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
-        Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
-
-        DownloadCommand cmd = new DownloadCommand(template, 100000L);
-        cmd.setCacheStore(cacheStore);
-        DownloadAnswer answer = (DownloadAnswer)resource.executeRequest(cmd);
-        Assert.assertTrue(answer.getResult());
-
-        Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
-        Mockito.when(template.getDataStore()).thenReturn(swift);
-        //download swift:
-        Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
-        TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
-        Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
-        Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore);
-        Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
-        CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true);
-        CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer)resource.executeRequest(cpyCmd);
-        Assert.assertTrue(copyCmdAnswer.getResult());
-
-        //list template
-        ListTemplateCommand listCmd = new ListTemplateCommand(swift);
-        ListTemplateAnswer listAnswer = (ListTemplateAnswer)resource.executeRequest(listCmd);
-
-        Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0);
-    }
-
-    public static Properties loadProperties() throws ConfigurationException {
-        Properties properties = new Properties();
-        final File file = PropertiesUtil.findConfigFile("agent.properties");
-        if (file == null) {
-            throw new ConfigurationException("Unable to find agent.properties.");
-        }
-
-        s_logger.info("agent.properties found at " + file.getAbsolutePath());
-
-        try {
-            properties.load(new FileInputStream(file));
-        } catch (final FileNotFoundException ex) {
-            throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
-        } catch (final IOException ex) {
-            throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
-        }
-        return properties;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java b/services/secondary-storage/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java
deleted file mode 100644
index e0ae4c5..0000000
--- a/services/secondary-storage/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.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 org.apache.cloudstack.storage.resource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.naming.ConfigurationException;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.cloud.utils.PropertiesUtil;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public class NfsSecondaryStorageResourceTest extends TestCase {
-    private static Map<String, Object> testParams;
-
-    private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResourceTest.class.getName());
-
-    NfsSecondaryStorageResource resource;
-
-    @Before
-    @Override
-    public void setUp() throws ConfigurationException {
-        s_logger.setLevel(Level.ALL);
-        resource = new NfsSecondaryStorageResource();
-        resource.setInSystemVM(true);
-        testParams = PropertiesUtil.toMap(loadProperties());
-        resource.configureStorageLayerClass(testParams);
-        Object testLocalRoot = testParams.get("testLocalRoot");
-        if (testLocalRoot != null) {
-            resource.setParentPath((String)testLocalRoot);
-        }
-    }
-
-    @Test
-    public void testMount() throws Exception {
-        String sampleUriStr = "cifs://192.168.1.128/CSHV3?user=administrator&password=1pass%40word1&foo=bar";
-        URI sampleUri = new URI(sampleUriStr);
-
-        s_logger.info("Check HostIp parsing");
-        String hostIpStr = resource.getUriHostIp(sampleUri);
-        Assert.assertEquals("Expected host IP " + sampleUri.getHost() + " and actual host IP " + hostIpStr + " differ.", sampleUri.getHost(), hostIpStr);
-
-        s_logger.info("Check option parsing");
-        String expected = "user=administrator,password=1pass@word1,foo=bar,";
-        String actualOpts = resource.parseCifsMountOptions(sampleUri);
-        Assert.assertEquals("Options should be " + expected + " and not " + actualOpts, expected, actualOpts);
-
-        // attempt a configured mount
-        final Map<String, Object> params = PropertiesUtil.toMap(loadProperties());
-        String sampleMount = (String)params.get("testCifsMount");
-        if (!sampleMount.isEmpty()) {
-            s_logger.info("functional test, mount " + sampleMount);
-            URI realMntUri = new URI(sampleMount);
-            String mntSubDir = resource.mountUri(realMntUri);
-            s_logger.info("functional test, umount " + mntSubDir);
-            resource.umount(resource.getMountingRoot() + mntSubDir, realMntUri);
-        } else {
-            s_logger.info("no entry for testCifsMount in " + "./conf/agent.properties - skip functional test");
-        }
-    }
-
-    public static Properties loadProperties() throws ConfigurationException {
-        Properties properties = new Properties();
-        final File file = PropertiesUtil.findConfigFile("agent.properties");
-        if (file == null) {
-            throw new ConfigurationException("Unable to find agent.properties.");
-        }
-
-        s_logger.info("agent.properties found at " + file.getAbsolutePath());
-
-        try {
-            properties.load(new FileInputStream(file));
-        } catch (final FileNotFoundException ex) {
-            throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
-        } catch (final IOException ex) {
-            throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
-        }
-        return properties;
-    }
-
-}


[25/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fix camelcasing inconsistency causing an assertion error.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3cfa5fbf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3cfa5fbf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3cfa5fbf

Branch: refs/heads/rbac
Commit: 3cfa5fbfe10a49cb14dbbd99a99c3c6424a7226e
Parents: 7f780f2
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 19:32:05 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 19:32:32 2014 +0100

----------------------------------------------------------------------
 .../VirtualNetworkApplianceManagerImpl.java     | 318 +++++++++----------
 1 file changed, 159 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3cfa5fbf/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 589b50c..413b410 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -42,6 +42,8 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd;
@@ -56,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
@@ -282,7 +283,7 @@ import com.cloud.vm.dao.VMInstanceDao;
  */
 @Local(value = {VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class})
 public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, VirtualMachineGuru,
-        Listener, Configurable {
+Listener, Configurable {
     private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
 
     @Inject
@@ -489,7 +490,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         if (!router.getState().equals(State.Stopped)) {
             s_logger.warn("Unable to upgrade router " + router.toString() + " in state " + router.getState());
             throw new InvalidParameterValueException("Unable to upgrade router " + router.toString() + " in state " + router.getState() +
-                "; make sure the router is stopped and not in an error state before upgrading.");
+                    "; make sure the router is stopped and not in an error state before upgrading.");
         }
 
         final ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
@@ -498,7 +499,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         // offering
         if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) {
             throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getUseLocalStorage() +
-                " is different from " + "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());
+                    " is different from " + "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());
         }
 
         router.setServiceOfferingId(serviceOfferingId);
@@ -512,7 +513,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean savePasswordToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         _userVmDao.loadDetails((UserVmVO)profile.getVirtualMachine());
 
         final VirtualMachineProfile updatedProfile = profile;
@@ -531,7 +532,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean saveSSHPublicKeyToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers,
-        final String sshPublicKey) throws ResourceUnavailableException {
+            final String sshPublicKey) throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId());
         _userVmDao.loadDetails(vm);
 
@@ -555,7 +556,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean saveUserDataToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId());
         _userVmDao.loadDetails(vm);
 
@@ -611,7 +612,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
                 for (final Long guestNtwkId : routerGuestNtwkIds) {
                     final UserStatisticsVO userStats =
-                        _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), guestNtwkId, null, router.getId(), router.getType().toString());
+                            _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), guestNtwkId, null, router.getId(), router.getType().toString());
                     if (userStats != null) {
                         final long currentBytesRcvd = userStats.getCurrentBytesReceived();
                         userStats.setCurrentBytesReceived(0);
@@ -633,7 +634,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
     public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException,
-        InsufficientCapacityException {
+    InsufficientCapacityException {
         final Account caller = CallContext.current().getCallingAccount();
 
         // verify parameters
@@ -661,7 +662,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     static final ConfigKey<Boolean> UseExternalDnsServers = new ConfigKey<Boolean>(Boolean.class, "use.external.dns", "Advanced", "false",
-        "Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null);
+            "Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null);
 
     static final ConfigKey<Boolean> routerVersionCheckEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "router.version.check", "true",
             "If true, router minimum required version is checked before sending command", false);
@@ -727,8 +728,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         final boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
         _offering =
-            new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true,
-                VirtualMachine.Type.DomainRouter, true);
+                new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true,
+                        VirtualMachine.Type.DomainRouter, true);
         _offering.setUniqueName(ServiceOffering.routerDefaultOffUniqueName);
         _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering);
 
@@ -800,7 +801,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         _networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), (endDate - System.currentTimeMillis()), (_usageAggregationRange * 60 * 1000),
-            TimeUnit.MILLISECONDS);
+                TimeUnit.MILLISECONDS);
 
         if (_routerCheckInterval > 0) {
             _checkExecutor.scheduleAtFixedRate(new CheckRouterTask(), _routerCheckInterval, _routerCheckInterval, TimeUnit.SECONDS);
@@ -823,7 +824,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     private VmDataCommand generateVmDataCommand(final VirtualRouter router, final String vmPrivateIpAddress, final String userData, final String serviceOffering, final String zoneName,
-        final String guestIpAddress, final String vmName, final String vmInstanceName, final long vmId, final String vmUuid, final String publicKey, final long guestNetworkId) {
+            final String guestIpAddress, final String vmName, final String vmInstanceName, final long vmId, final String vmUuid, final String publicKey, final long guestNetworkId) {
         final VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd());
 
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
@@ -899,25 +900,25 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                             //Send network usage command for public nic in VPC VR
                             //Send network usage command for isolated guest nic of non VPC VR
                             if ((forVpc && network.getTrafficType() == TrafficType.Public) ||
-                                (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
+                                    (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
                                 final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(), forVpc, routerNic.getIp4Address());
                                 final String routerType = router.getType().toString();
                                 final UserStatisticsVO previousStats =
-                                    _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
-                                        router.getId(), routerType);
+                                        _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
+                                                router.getId(), routerType);
                                 NetworkUsageAnswer answer = null;
                                 try {
                                     answer = (NetworkUsageAnswer)_agentMgr.easySend(router.getHostId(), usageCmd);
                                 } catch (final Exception e) {
                                     s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(),
-                                        e);
+                                            e);
                                     continue;
                                 }
 
                                 if (answer != null) {
                                     if (!answer.getResult()) {
                                         s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " +
-                                            router.getHostId() + "; details: " + answer.getDetails());
+                                                router.getHostId() + "; details: " + answer.getDetails());
                                         continue;
                                     }
                                     try {
@@ -930,26 +931,26 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                             @Override
                                             public void doInTransactionWithoutResult(final TransactionStatus status) {
                                                 final UserStatisticsVO stats =
-                                                    _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(),
-                                                        (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
+                                                        _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(),
+                                                                (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                                                 if (stats == null) {
                                                     s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                                     return;
                                                 }
 
                                                 if (previousStats != null &&
-                                                    ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
+                                                        ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
                                                     s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
-                                                        "Ignoring current answer. Router: " + answerFinal.getRouterName() + " Rcvd: " + answerFinal.getBytesReceived() +
-                                                        "Sent: " + answerFinal.getBytesSent());
+                                                            "Ignoring current answer. Router: " + answerFinal.getRouterName() + " Rcvd: " + answerFinal.getBytesReceived() +
+                                                            "Sent: " + answerFinal.getBytesSent());
                                                     return;
                                                 }
 
                                                 if (stats.getCurrentBytesReceived() > answerFinal.getBytesReceived()) {
                                                     if (s_logger.isDebugEnabled()) {
                                                         s_logger.debug("Received # of bytes that's less than the last one.  " +
-                                                            "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
-                                                            answerFinal.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived());
+                                                                "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
+                                                                answerFinal.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived());
                                                     }
                                                     stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                                                 }
@@ -957,8 +958,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                                 if (stats.getCurrentBytesSent() > answerFinal.getBytesSent()) {
                                                     if (s_logger.isDebugEnabled()) {
                                                         s_logger.debug("Received # of bytes that's less than the last one.  " +
-                                                            "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
-                                                            answerFinal.getBytesSent() + " Stored: " + stats.getCurrentBytesSent());
+                                                                "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
+                                                                answerFinal.getBytesSent() + " Stored: " + stats.getCurrentBytesSent());
                                                     }
                                                     stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                                 }
@@ -974,7 +975,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
                                     } catch (final Exception e) {
                                         s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() +
-                                            "; Tx: " + answer.getBytesSent());
+                                                "; Tx: " + answer.getBytesSent());
                                     }
                                 }
                             }
@@ -1019,8 +1020,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                     _userStatsDao.update(stat.getId(), stat);
                                     //insert into op_user_stats_log
                                     final UserStatsLogVO statsLog =
-                                        new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat.getCurrentBytesReceived(),
-                                            stat.getCurrentBytesSent(), stat.getAggBytesReceived(), stat.getAggBytesSent(), updatedTime);
+                                            new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat.getCurrentBytesReceived(),
+                                                    stat.getCurrentBytesSent(), stat.getAggBytesReceived(), stat.getAggBytesSent(), updatedTime);
                                     _userStatsLogDao.persist(statsLog);
                                 }
                                 s_logger.debug("Successfully updated aggregate network stats");
@@ -1108,8 +1109,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         if (oldState != conn.getState()) {
                             final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switch from " + oldState + " to " + conn.getState();
                             final String context =
-                                "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " +
-                                    " just switch from " + oldState + " to " + conn.getState();
+                                    "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " +
+                                            " just switch from " + oldState + " to " + conn.getState();
                             s_logger.info(context);
                             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
                         }
@@ -1169,7 +1170,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             if (prevState != currState) {
                 final String title = "Redundant virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
                 final String context =
-                    "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " + " just switch from " + prevState + " to " + currState;
+                        "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " + " just switch from " + prevState + " to " + currState;
                 s_logger.info(context);
                 if (currState == RedundantState.MASTER) {
                     _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
@@ -1275,13 +1276,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         if (networkRouterMaps.containsKey(routerGuestNtwkId)) {
                             final DomainRouterVO dupRouter = networkRouterMaps.get(routerGuestNtwkId);
                             final String title =
-                                "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
+                                    "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
                             final String context =
-                                "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " + dupRouter.getHostName() + ", id: " +
-                                    router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. ";
+                                    "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " + dupRouter.getHostName() + ", id: " +
+                                            router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. ";
                             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
                             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterId(), dupRouter.getPodIdToDeployIn(), title,
-                                context);
+                                    context);
                             s_logger.warn(context);
                         } else {
                             networkRouterMaps.put(routerGuestNtwkId, router);
@@ -1386,7 +1387,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             } else if (maxPriority > 200) {
                 s_logger.error("Too many times fail-over happened! Current maximum priority is too high as " + maxPriority + "!");
                 throw new InsufficientVirtualNetworkCapcityException("Too many times fail-over happened! Current maximum priority is too high as " + maxPriority + "!",
-                    guestNetwork.getId());
+                        guestNetwork.getId());
             }
             priority = maxPriority - DEFAULT_DELTA + 1;
         }
@@ -1417,9 +1418,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         final String errMsg =
-            "Cannot find an available cluster in Pod " + podId + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, " +
-                "please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod" +
-                " with Ovm cluster. And there is at least one host in UP status in that cluster.";
+                "Cannot find an available cluster in Pod " + podId + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, " +
+                        "please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod" +
+                        " with Ovm cluster. And there is at least one host in UP status in that cluster.";
         throw new CloudRuntimeException(errMsg);
     }
 
@@ -1445,7 +1446,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @DB
     protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, Account owner, final boolean isRedundant,
-        final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+            final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
 
         List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
         final Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
@@ -1460,7 +1461,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         try {
 
             assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup ||
-                guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
+                    guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
             assert guestNetwork.getTrafficType() == TrafficType.Guest;
 
             // 1) Get deployment plan and find out the list of routers
@@ -1565,7 +1566,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 final DeploymentPlan plan = planAndRouters.first();
                 for (int i = 0; i < count; i++) {
                     final LinkedHashMap<Network, NicProfile> networks =
-                        createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
+                            createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
                     //don't start the router as we are holding the network lock that needs to be released at the end of router allocation
                     final DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null);
 
@@ -1605,9 +1606,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected DomainRouterVO deployRouter(final Account owner, final DeployDestination dest, final DeploymentPlan plan, final Map<Param, Object> params, final boolean isRedundant,
-        final VirtualRouterProvider vrProvider, final long svcOffId, final Long vpcId, final LinkedHashMap<Network, NicProfile> networks, final boolean startRouter,
-        final List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException,
-        InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
+            final VirtualRouterProvider vrProvider, final long svcOffId, final Long vpcId, final LinkedHashMap<Network, NicProfile> networks, final boolean startRouter,
+            final List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException,
+            InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
 
         final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
 
@@ -1628,23 +1629,23 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
                 String templateName = null;
                 switch (hType) {
-                    case XenServer:
-                        templateName = RouterTemplateXen.valueIn(dest.getDataCenter().getId());
-                        break;
-                    case KVM:
-                        templateName = RouterTemplateKvm.valueIn(dest.getDataCenter().getId());
-                        break;
-                    case VMware:
-                        templateName = RouterTemplateVmware.valueIn(dest.getDataCenter().getId());
-                        break;
-                    case Hyperv:
-                        templateName = RouterTemplateHyperV.valueIn(dest.getDataCenter().getId());
-                        break;
-                    case LXC:
-                        templateName = RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
-                        break;
-                    default:
-                        break;
+                case XenServer:
+                    templateName = RouterTemplateXen.valueIn(dest.getDataCenter().getId());
+                    break;
+                case KVM:
+                    templateName = RouterTemplateKvm.valueIn(dest.getDataCenter().getId());
+                    break;
+                case VMware:
+                    templateName = RouterTemplateVmware.valueIn(dest.getDataCenter().getId());
+                    break;
+                case Hyperv:
+                    templateName = RouterTemplateHyperV.valueIn(dest.getDataCenter().getId());
+                    break;
+                case LXC:
+                    templateName = RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
+                    break;
+                default:
+                    break;
                 }
                 final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
 
@@ -1660,9 +1661,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
 
                 router =
-                    new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(),
-                        template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, RedundantState.UNKNOWN,
-                        offerHA, false, vpcId);
+                        new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(),
+                                template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, RedundantState.UNKNOWN,
+                                offerHA, false, vpcId);
                 router.setDynamicallyScalable(template.isDynamicallyScalable());
                 router.setRole(Role.VIRTUAL_ROUTER);
                 router = _routerDao.persist(router);
@@ -1705,7 +1706,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected List<HypervisorType> getHypervisors(final DeployDestination dest, final DeploymentPlan plan, final List<HypervisorType> supportedHypervisors)
-        throws InsufficientServerCapacityException {
+            throws InsufficientServerCapacityException {
         List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
 
         if (dest.getCluster() != null) {
@@ -1737,16 +1738,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             final String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : "";
             if (plan.getPodId() != null) {
                 throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the pod " + errMsg, Pod.class,
-                    plan.getPodId());
+                        plan.getPodId());
             }
             throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the zone " + errMsg, DataCenter.class,
-                dest.getDataCenter().getId());
+                    dest.getDataCenter().getId());
         }
         return hypervisors;
     }
 
     protected LinkedHashMap<Network, NicProfile> createRouterNetworks(final Account owner, final boolean isRedundant, final DeploymentPlan plan, final Network guestNetwork,
-        final Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
+            final Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
 
         boolean setupPublicNetwork = false;
         if (publicNetwork != null) {
@@ -1773,7 +1774,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                             defaultNetworkStartIp = startIp;
                         } else if (s_logger.isDebugEnabled()) {
                             s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() +
-                                " is already allocated, can't use it for domain router; will get random ip address from the range");
+                                    " is already allocated, can't use it for domain router; will get random ip address from the range");
                         }
                     }
                 }
@@ -1788,7 +1789,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                             defaultNetworkStartIpv6 = startIpv6;
                         } else if (s_logger.isDebugEnabled()) {
                             s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
-                                " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
+                                    " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
                         }
                     }
                 }
@@ -1884,7 +1885,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     private DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException,
-        InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+    InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
 
         if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
             return this.start(router, user, caller, params, null);
@@ -1910,9 +1911,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                     if (routerToBeAvoid != null) {
                         throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" +
-                            ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" +
-                            rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class,
-                            rrouter.getDataCenterId());
+                                ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" +
+                                rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class,
+                                rrouter.getDataCenterId());
                     }
                     routerToBeAvoid = rrouter;
                 }
@@ -1957,7 +1958,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, final Account owner, final Map<Param, Object> params,
-        final boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+            final boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
 
         final List<DomainRouterVO> routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params);
 
@@ -1965,7 +1966,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected List<DomainRouterVO> startRouters(final Map<Param, Object> params, final List<DomainRouterVO> routers) throws StorageUnavailableException,
-        InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+    InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
         List<DomainRouterVO> runningRouters = null;
 
         if (routers != null) {
@@ -2056,7 +2057,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 // DOMR control command is sent over management server in VMware
                 if (dest.getHost().getHypervisorType() == HypervisorType.VMware || dest.getHost().getHypervisorType() == HypervisorType.Hyperv) {
                     s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: " + dest.getPod().getCidrAddress() + "/" +
- dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + ApiServiceConfiguration.ManagementHostIPAdr.value());
+                            dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + ApiServiceConfiguration.ManagementHostIPAdr.value());
 
                     if (s_logger.isInfoEnabled()) {
                         s_logger.info("Add management server explicit route to DomR.");
@@ -2248,7 +2249,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         final Network network = _networkDao.findById(nic.getNetworkId());
         final String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
         final PvlanSetupCommand cmd =
-            PvlanSetupCommand.createDhcpSetup(op, nic.getBroadCastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
+                PvlanSetupCommand.createDhcpSetup(op, nic.getBroadCastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
         // In fact we send command to the host of router, we're not programming router but the host
         Answer answer = null;
         try {
@@ -2269,7 +2270,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean finalizeDeployment(final Commands cmds, final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         final DomainRouterVO router = _routerDao.findById(profile.getId());
 
         final List<NicProfile> nics = profile.getNics();
@@ -2339,7 +2340,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         // get the list of sevices for this network to monitor
         final List<MonitoringServiceVO> services = new ArrayList<MonitoringServiceVO>();
         if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VirtualRouter) ||
-            _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VirtualRouter)) {
+                _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VirtualRouter)) {
             final MonitoringServiceVO dhcpService = _monitorServiceDao.getServiceByName(MonitoringService.Service.Dhcp.toString());
             if (dhcpService != null) {
                 services.add(dhcpService);
@@ -2357,9 +2358,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         final List<MonitorServiceTO> servicesTO = new ArrayList<MonitorServiceTO>();
         for (final MonitoringServiceVO service : services) {
-            final MonitorServiceTO serviceTO =
-                new MonitorServiceTO(service.getService(), service.getProcessname(), service.getServiceName(), service.getServicePath(), service.getPidFile(),
-                    service.isDefaultService());
+            final MonitorServiceTO serviceTO = new MonitorServiceTO(service.getService(), service.getProcessName(), service.getServiceName(), service.getServicePath(),
+                    service.getServicePidFile(), service.isDefaultService());
             servicesTO.add(serviceTO);
         }
 
@@ -2538,7 +2538,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         final Network guestNetwork = _networkDao.findById(guestNetworkId);
         if (guestNetwork.getGuestType() == GuestType.Shared && _networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Dhcp, provider)) {
             final Map<Network.Capability, String> dhcpCapabilities =
-                _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(_networkDao.findById(guestNetworkId).getNetworkOfferingId()), Service.Dhcp);
+                    _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(_networkDao.findById(guestNetworkId).getNetworkOfferingId()), Service.Dhcp);
             final String supportsMultipleSubnets = dhcpCapabilities.get(Network.Capability.DhcpAccrossMultipleSubnets);
             if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) {
                 final List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(guestNetworkId, NicIpAlias.state.revoked);
@@ -2579,7 +2579,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(final VirtualRouter router, final Provider provider, final Long guestNetworkId,
-        final com.cloud.network.IpAddress.State... skipInStates) {
+            final com.cloud.network.IpAddress.State... skipInStates) {
         final long ownerId = router.getAccountId();
         final List<? extends IpAddress> userIps;
 
@@ -2713,7 +2713,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             if (router.getState() != State.Running) {
                 s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
                 throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class,
-                    network.getDataCenterId());
+                        network.getDataCenterId());
             }
 
             final Commands cmds = new Commands(Command.OnError.Stop);
@@ -2728,16 +2728,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             Answer answer = cmds.getAnswer("users");
             if (!answer.getResult()) {
                 s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " +
-                    router.getInstanceName() + " due to " + answer.getDetails());
+                        router.getInstanceName() + " due to " + answer.getDetails());
                 throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " +
-                    vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
+                        vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
             }
             answer = cmds.getAnswer("startVpn");
             if (!answer.getResult()) {
                 s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " +
-                    router.getInstanceName() + " due to " + answer.getDetails());
+                        router.getInstanceName() + " due to " + answer.getDetails());
                 throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " +
-                    router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
+                        router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
             }
 
         }
@@ -2763,7 +2763,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             } else {
                 s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
                 throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class,
-                    network.getDataCenterId());
+                        network.getDataCenterId());
             }
         }
 
@@ -2771,7 +2771,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     private DomainRouterVO start(DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params, final DeploymentPlan planToDeploy)
-        throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+            throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Starting router " + router);
         try {
             _itMgr.advanceStart(router.getUuid(), params, planToDeploy, null);
@@ -2805,7 +2805,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean configDhcpForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getId());
         _userVmDao.loadDetails(vm);
 
@@ -2814,11 +2814,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         if (router.getState() != State.Running) {
             s_logger.warn("Failed to configure dhcp: router not in running state");
             throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class,
-                network.getDataCenterId());
+                    network.getDataCenterId());
         }
         //check if this is not the primary subnet.
         final NicVO domr_guest_nic =
-            _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(nic.getNetworkId(), router.getId()), VirtualMachine.Type.DomainRouter);
+                _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(nic.getNetworkId(), router.getId()), VirtualMachine.Type.DomainRouter);
         //check if the router ip address and the vm ip address belong to same subnet.
         //if they do not belong to same netwoek check for the alias ips. if not create one.
         // This should happen only in case of Basic and Advanced SG enabled networks.
@@ -2847,12 +2847,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         }
                         if (dc.getNetworkType() == NetworkType.Basic) {
                             routerPublicIP =
-                                _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached,
-                                    vlanDbIdList, nic.getNetworkId(), null, false);
+                                    _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached,
+                                            vlanDbIdList, nic.getNetworkId(), null, false);
                         } else {
                             routerPublicIP =
-                                _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList,
-                                    nic.getNetworkId(), null, false);
+                                    _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList,
+                                            nic.getNetworkId(), null, false);
                         }
 
                         routerAliasIp = routerPublicIP.getAddress().addr();
@@ -2864,8 +2864,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
                 //this means we did not create a ip alis on the router.
                 final NicIpAliasVO alias =
-                    new NicIpAliasVO(domr_guest_nic.getId(), routerAliasIp, router.getId(), CallContext.current().getCallingAccountId(), network.getDomainId(),
-                        nic.getNetworkId(), nic.getGateway(), nic.getNetmask());
+                        new NicIpAliasVO(domr_guest_nic.getId(), routerAliasIp, router.getId(), CallContext.current().getCallingAccountId(), network.getDomainId(),
+                                nic.getNetworkId(), nic.getGateway(), nic.getNetmask());
                 alias.setAliasCount((routerPublicIP.getIpMacAddress()));
                 _nicIpAliasDao.persist(alias);
                 final List<IpAliasTO> ipaliasTo = new ArrayList<IpAliasTO>();
@@ -2898,14 +2898,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         if (routers == null || routers.isEmpty()) {
             s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
             throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class,
-                network.getDataCenterId());
+                    network.getDataCenterId());
         }
 
         for (final DomainRouterVO router : routers) {
             if (router.getState() != State.Running) {
                 s_logger.warn("Failed to add/remove VPN users: router not in running state");
                 throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class,
-                    network.getDataCenterId());
+                        network.getDataCenterId());
             }
 
             final Commands cmds = new Commands(Command.OnError.Continue);
@@ -2941,7 +2941,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         if (s_logger.isTraceEnabled()) {
             s_logger.trace("applyDhcpEntry(" + network.getCidr() + ", " + nic.getMacAddress() + ", " + profile.getUuid() + ", " + dest.getHost() + ", " + routers + ")");
         }
@@ -2955,7 +2955,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         boolean podLevelException = false;
         //for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
         if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest &&
-            network.getGuestType() == Network.GuestType.Shared) {
+                network.getGuestType() == Network.GuestType.Shared) {
             podLevelException = true;
         }
 
@@ -3019,7 +3019,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean applyUserData(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getId());
         _userVmDao.loadDetails(vm);
 
@@ -3030,7 +3030,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         boolean podLevelException = false;
         //for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
         if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest &&
-            network.getGuestType() == Network.GuestType.Shared) {
+                network.getGuestType() == Network.GuestType.Shared) {
             podLevelException = true;
         }
 
@@ -3073,12 +3073,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     //FIXME add partial success and STOP state support
-        public
-        String[] applyVpnUsers(final Network network, final List<? extends VpnUser> users, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
+    public
+    String[] applyVpnUsers(final Network network, final List<? extends VpnUser> users, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
         if (routers == null || routers.isEmpty()) {
             s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
             throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class,
-                network.getDataCenterId());
+                    network.getDataCenterId());
         }
 
         boolean agentResults = true;
@@ -3087,7 +3087,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             if (router.getState() != State.Running) {
                 s_logger.warn("Failed to add/remove VPN users: router not in running state");
                 throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class,
-                    network.getDataCenterId());
+                        network.getDataCenterId());
             }
 
             final Commands cmds = new Commands(Command.OnError.Continue);
@@ -3119,7 +3119,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException,
-        ConcurrentOperationException {
+    ConcurrentOperationException {
         final Account caller = CallContext.current().getCallingAccount();
         final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
 
@@ -3240,8 +3240,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
 
                 final IpAddressTO ip =
-                    new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress,
-                        networkRate, ipAddr.isOneToOneNat());
+                        new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress,
+                                networkRate, ipAddr.isOneToOneNat());
 
                 ip.setTrafficType(network.getTrafficType());
                 ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
@@ -3339,8 +3339,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         final Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
         final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
         final NicProfile nicProfile =
-            new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
-                _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
+                new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
+                        _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
         final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
         String maxconn = null;
         if (offering.getConcurrentConnections() == null) {
@@ -3350,8 +3350,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         final LoadBalancerConfigCommand cmd =
-            new LoadBalancerConfigCommand(lbs, routerPublicIp, getRouterIpInNetwork(guestNetworkId, router.getId()), router.getPrivateIpAddress(), _itMgr.toNicTO(
-                nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
+                new LoadBalancerConfigCommand(lbs, routerPublicIp, getRouterIpInNetwork(guestNetworkId, router.getId()), router.getPrivateIpAddress(), _itMgr.toNicTO(
+                        nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
 
         cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
         cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
@@ -3381,7 +3381,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         final String cidr = getVpnCidr(vpn);
         final RemoteAccessVpnCfgCommand startVpnCmd =
-            new RemoteAccessVpnCfgCommand(isCreate, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey(), (vpn.getVpcId() != null));
+                new RemoteAccessVpnCfgCommand(isCreate, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey(), (vpn.getVpcId() != null));
         startVpnCmd.setLocalCidr(cidr);
         startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
         startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
@@ -3399,7 +3399,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         if (password != null && nic.isDefaultNic()) {
             final String encodedPassword = PasswordGenerator.rot13(password);
             final SavePasswordCommand cmd =
-                new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
+                    new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
             cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
             cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
             cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
@@ -3414,9 +3414,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
         final String zoneName = _dcDao.findById(router.getDataCenterId()).getName();
         cmds.addCommand(
-            "vmdata",
-            generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
-                vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId()));
+                "vmdata",
+                generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
+                        vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId()));
 
     }
 
@@ -3441,7 +3441,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     private void createDhcpEntryCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final Commands cmds) {
         final DhcpEntryCommand dhcpCommand =
-            new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address(), _networkModel.getExecuteInSeqNtwkElmtCmd());
+                new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address(), _networkModel.getExecuteInSeqNtwkElmtCmd());
         final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
         final Nic defaultNic = findGatewayIp(vm.getId());
         String gatewayIp = defaultNic.getGateway();
@@ -3484,7 +3484,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             final DhcpTO DhcpTO = new DhcpTO(ipAliasVO.getIp4Address(), ipAliasVO.getGateway(), ipAliasVO.getNetmask(), ipAliasVO.getStartIpOfSubnet());
             if (s_logger.isTraceEnabled()) {
                 s_logger.trace("configDnsMasq : adding ip {" + DhcpTO.getGateway() + ", " + DhcpTO.getNetmask() + ", " + DhcpTO.getRouterIp() + ", " +
-                    DhcpTO.getStartIpOfSubnet() + "}");
+                        DhcpTO.getStartIpOfSubnet() + "}");
             }
             ipList.add(DhcpTO);
             ipAliasVO.setVmId(router.getId());
@@ -3517,7 +3517,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         for (final UserVmVO vm : vms) {
             boolean createDhcp = true;
             if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue() &&
-                _dnsBasicZoneUpdates.equalsIgnoreCase("pod")) {
+                    _dnsBasicZoneUpdates.equalsIgnoreCase("pod")) {
                 createDhcp = false;
             }
             if (createDhcp) {
@@ -3565,7 +3565,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) {
             return;
         }
@@ -3575,11 +3575,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
         if (!connectedRouters.get(0).getIsRedundantRouter()) {
             throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, connectedRouters.get(0)
-                .getDataCenterId());
+                    .getDataCenterId());
         }
         if (!disconnectedRouters.get(0).getIsRedundantRouter()) {
             throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, disconnectedRouters.get(0)
-                .getDataCenterId());
+                    .getDataCenterId());
         }
 
         final DomainRouterVO connectedRouter = (DomainRouterVO)connectedRouters.get(0);
@@ -3590,10 +3590,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
         final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason;
         final String context =
-            "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() +
+                "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() +
                 ") would be stopped after connecting back, due to: " + reason;
         _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title,
-            context);
+                context);
         disconnectedRouter.setStopPending(true);
         disconnectedRouter = _routerDao.persist(disconnectedRouter);
 
@@ -3618,7 +3618,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean associatePublicIP(final Network network, final List<? extends PublicIpAddress> ipAddress, final List<? extends VirtualRouter> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         if (ipAddress == null || ipAddress.isEmpty()) {
             s_logger.debug("No ip association rules to be applied for network " + network.getId());
             return true;
@@ -3635,7 +3635,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean applyFirewallRules(final Network network, final List<? extends FirewallRule> rules, final List<? extends VirtualRouter> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         if (rules == null || rules.isEmpty()) {
             s_logger.debug("No firewall rules to be applied for network " + network.getId());
             return true;
@@ -3674,7 +3674,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     public boolean applyLoadBalancingRules(final Network network, final List<? extends LoadBalancingRule> rules, final List<? extends VirtualRouter> routers)
-        throws ResourceUnavailableException {
+            throws ResourceUnavailableException {
         if (rules == null || rules.isEmpty()) {
             s_logger.debug("No lb rules to be applied for network " + network.getId());
             return true;
@@ -3787,7 +3787,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     protected boolean applyRules(final Network network, final List<? extends VirtualRouter> routers, final String typeString, final boolean isPodLevelException, final Long podId,
-        final boolean failWhenDisconnect, final RuleApplier applier) throws ResourceUnavailableException {
+            final boolean failWhenDisconnect, final RuleApplier applier) throws ResourceUnavailableException {
         if (routers == null || routers.isEmpty()) {
             s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
             throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
@@ -3810,7 +3810,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 if (router.isStopPending()) {
                     if (_hostDao.findById(router.getHostId()).getState() == Status.Up) {
                         throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() +
-                            " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
+                                " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
                     }
                     s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
                     continue;
@@ -3840,7 +3840,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
                 }
                 throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class,
-                    router.getDataCenterId());
+                        router.getDataCenterId());
             }
         }
 
@@ -3895,7 +3895,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             for (final StaticNat rule : rules) {
                 final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
                 final StaticNatRuleTO ruleTO =
-                    new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
+                        new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                 rulesTO.add(ruleTO);
             }
         }
@@ -4012,12 +4012,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 //Send network usage command for public nic in VPC VR
                 //Send network usage command for isolated guest nic of non VPC VR
                 if ((forVpc && network.getTrafficType() == TrafficType.Public) ||
-                    (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
+                        (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
                     final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(), forVpc, routerNic.getIp4Address());
                     final String routerType = router.getType().toString();
                     final UserStatisticsVO previousStats =
-                        _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
-                            router.getId(), routerType);
+                            _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
+                                    router.getId(), routerType);
                     NetworkUsageAnswer answer = null;
                     try {
                         answer = (NetworkUsageAnswer)_agentMgr.easySend(router.getHostId(), usageCmd);
@@ -4029,7 +4029,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     if (answer != null) {
                         if (!answer.getResult()) {
                             s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() +
-                                "; details: " + answer.getDetails());
+                                    "; details: " + answer.getDetails());
                             continue;
                         }
                         try {
@@ -4043,25 +4043,25 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                 @Override
                                 public void doInTransactionWithoutResult(final TransactionStatus status) {
                                     final UserStatisticsVO stats =
-                                        _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
-                                            router.getId(), routerType);
+                                            _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null),
+                                                    router.getId(), routerType);
                                     if (stats == null) {
                                         s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                         return;
                                     }
 
                                     if (previousStats != null &&
-                                        ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
+                                            ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
                                         s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " + "Ignoring current answer. Router: " +
-                                            answerFinal.getRouterName() + " Rcvd: " + answerFinal.getBytesReceived() + "Sent: " + answerFinal.getBytesSent());
+                                                answerFinal.getRouterName() + " Rcvd: " + answerFinal.getBytesReceived() + "Sent: " + answerFinal.getBytesSent());
                                         return;
                                     }
 
                                     if (stats.getCurrentBytesReceived() > answerFinal.getBytesReceived()) {
                                         if (s_logger.isDebugEnabled()) {
                                             s_logger.debug("Received # of bytes that's less than the last one.  " +
-                                                "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
-                                                answerFinal.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived());
+                                                    "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
+                                                    answerFinal.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived());
                                         }
                                         stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                                     }
@@ -4069,8 +4069,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                     if (stats.getCurrentBytesSent() > answerFinal.getBytesSent()) {
                                         if (s_logger.isDebugEnabled()) {
                                             s_logger.debug("Received # of bytes that's less than the last one.  " +
-                                                "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
-                                                answerFinal.getBytesSent() + " Stored: " + stats.getCurrentBytesSent());
+                                                    "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " +
+                                                    answerFinal.getBytesSent() + " Stored: " + stats.getCurrentBytesSent());
                                         }
                                         stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                     }
@@ -4085,7 +4085,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                             });
                         } catch (final Exception e) {
                             s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() + "; Tx: " +
-                                answer.getBytesSent());
+                                    answer.getBytesSent());
                         }
                     }
                 }
@@ -4124,7 +4124,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
                 routers = _routerDao.listRunningByAccountId(account.getId());
             } else {
-            //List by domainId, account name not specified
+                //List by domainId, account name not specified
                 routers = _routerDao.listRunningByDomain(domainId);
             }
             params++;
@@ -4187,9 +4187,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 params.put("id", "" + router.getId());
                 params.put("ctxStartEventId", "1");
                 final AsyncJobVO job =
-                    new AsyncJobVO(UUID.randomUUID().toString(), User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), ApiGsonHelper.getBuilder()
-                        .create()
-                        .toJson(params), router.getId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null);
+                        new AsyncJobVO(UUID.randomUUID().toString(), User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), ApiGsonHelper.getBuilder()
+                                .create()
+                                .toJson(params), router.getId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null);
                 job.setDispatcher(_asyncDispatcher.getName());
                 final long jobId = _asyncMgr.submitAsyncJob(job);
                 jobIds.add(jobId);


[34/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
fixBugs finding

fm.equals(format) breaks equals contract

Signed-off-by: Daan Hoogland <da...@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cecb216c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cecb216c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cecb216c

Branch: refs/heads/rbac
Commit: cecb216caa22541d243369e76ef80b4f2225b728
Parents: 13e0f29
Author: Ian Southam <is...@schubergphilis.com>
Authored: Wed Feb 5 18:02:34 2014 +0100
Committer: Daan Hoogland <da...@onecht.net>
Committed: Thu Feb 6 10:32:06 2014 +0100

----------------------------------------------------------------------
 .../apache/cloudstack/storage/image/format/ImageFormatHelper.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cecb216c/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
index 9523d24..5a424cb 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
@@ -36,7 +36,7 @@ public class ImageFormatHelper {
 
     public static ImageFormat getFormat(String format) {
         for (ImageFormat fm : formats) {
-            if (fm.equals(format)) {
+            if (fm.toString().equals(format)) {
                 return fm;
             }
         }


[47/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6049: Give priority to cache stores where data object is
already there instead of randomly picking one in case there are multiple
cache stores in the scope.



Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bac2c1e5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bac2c1e5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bac2c1e5

Branch: refs/heads/rbac
Commit: bac2c1e5b49a1b5c4be37ca17d5e4829a2906782
Parents: 04766c6
Author: Min Chen <mi...@citrix.com>
Authored: Thu Feb 6 17:19:24 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Thu Feb 6 17:19:24 2014 -0800

----------------------------------------------------------------------
 .../api/storage/StorageCacheManager.java        |  2 ++
 .../cache/allocator/StorageCacheAllocator.java  |  3 ++
 .../allocator/StorageCacheRandomAllocator.java  | 38 ++++++++++++++++++++
 .../cache/manager/StorageCacheManagerImpl.java  | 13 +++++++
 .../motion/AncientDataMotionStrategy.java       |  2 +-
 5 files changed, 57 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bac2c1e5/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java
index 6d1ac2d..b8aeb5c 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java
@@ -21,6 +21,8 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
 public interface StorageCacheManager {
     DataStore getCacheStorage(Scope scope);
 
+    DataStore getCacheStorage(DataObject data, Scope scope);
+
     DataObject createCacheObject(DataObject data, Scope scope);
 
     /**

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bac2c1e5/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java
index 4259d9e..96251c5 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java
@@ -18,9 +18,12 @@
  */
 package org.apache.cloudstack.storage.cache.allocator;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
 
 public interface StorageCacheAllocator {
     DataStore getCacheStore(Scope scope);
+
+    DataStore getCacheStore(DataObject data, Scope scope);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bac2c1e5/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
index 7c11561..b4ef595 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
@@ -26,9 +26,13 @@ import javax.inject.Inject;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
+import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 
 import com.cloud.storage.ScopeType;
 
@@ -37,6 +41,8 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator {
     private static final Logger s_logger = Logger.getLogger(StorageCacheRandomAllocator.class);
     @Inject
     DataStoreManager dataStoreMgr;
+    @Inject
+    ObjectInDataStoreManager objectInStoreMgr;
 
     @Override
     public DataStore getCacheStore(Scope scope) {
@@ -54,4 +60,36 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator {
         Collections.shuffle(cacheStores);
         return cacheStores.get(0);
     }
+
+    @Override
+    public DataStore getCacheStore(DataObject data, Scope scope) {
+        if (scope.getScopeType() != ScopeType.ZONE) {
+            s_logger.debug("Can only support zone wide cache storage");
+            return null;
+        }
+
+        List<DataStore> cacheStores = dataStoreMgr.getImageCacheStores(scope);
+        if (cacheStores.size() <= 0) {
+            s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId());
+            return null;
+        }
+
+        // if there are multiple cache stores, we give priority to the one where data is already there
+        if (cacheStores.size() > 1) {
+            for (DataStore store : cacheStores) {
+                DataObjectInStore obj = objectInStoreMgr.findObject(data, store);
+                if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready) {
+                    s_logger.debug("pick the cache store " + store.getId() + " where data is already there");
+                    return store;
+                }
+            }
+
+            // otherwise, just random pick one
+            Collections.shuffle(cacheStores);
+        }
+        return cacheStores.get(0);
+
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bac2c1e5/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
index fe2543c..3a502d1 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
@@ -90,6 +90,19 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
         return null;
     }
 
+
+    @Override
+    public DataStore getCacheStorage(DataObject data, Scope scope) {
+        for (StorageCacheAllocator allocator : storageCacheAllocator) {
+            DataStore store = allocator.getCacheStore(data, scope);
+            if (store != null) {
+                return store;
+            }
+        }
+        return null;
+    }
+
+
     protected List<DataStore> getCacheStores() {
         QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class);
         sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bac2c1e5/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index 7ae793f..0556479 100644
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -195,7 +195,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
 
     protected DataObject cacheSnapshotChain(SnapshotInfo snapshot, Scope scope) {
         DataObject leafData = null;
-        DataStore store = cacheMgr.getCacheStorage(scope);
+        DataStore store = cacheMgr.getCacheStorage(snapshot, scope);
         while (snapshot != null) {
             DataObject cacheData = cacheMgr.createCacheObject(snapshot, store);
             if (leafData == null) {


[23/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
SnapshotDetailsVO doesn't have a display field even though it is required in the searchbuilder in ResourceDetailsDaoBase

java.lang.AssertionError: Searching for a field that's not there: display
    at com.cloud.utils.db.SearchBase.set(SearchBase.java:219)
    at com.cloud.utils.db.SearchBase$Interceptor.intercept(SearchBase.java:475)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/adf6026d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/adf6026d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/adf6026d

Branch: refs/heads/rbac
Commit: adf6026d2117f42ea625a1d3748493fededcff40
Parents: 8a9d979
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 17:44:39 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 17:46:33 2014 +0100

----------------------------------------------------------------------
 .../cloudstack/resourcedetail/ResourceDetailsDaoBase.java       | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adf6026d/engine/schema/src/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java
index 2d08644..60d7f16 100644
--- a/engine/schema/src/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java
+++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java
@@ -34,7 +34,10 @@ public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends G
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("resourceId", AllFieldsSearch.entity().getResourceId(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("display", AllFieldsSearch.entity().isDisplay(), SearchCriteria.Op.EQ);
+        // FIXME SnapshotDetailsVO doesn't have a display field
+        if (_allAttributes.containsKey("display")) {
+            AllFieldsSearch.and("display", AllFieldsSearch.entity().isDisplay(), SearchCriteria.Op.EQ);
+        }
         AllFieldsSearch.done();
     }
 


[36/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
test: Expand LibvirtDomainXMLParserTest with Interface test


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1baebebd
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1baebebd
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1baebebd

Branch: refs/heads/rbac
Commit: 1baebebda643fd0f4a21abb5c40eea3d5ec6c034
Parents: 41c7e22
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Thu Feb 6 14:40:40 2014 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Thu Feb 6 14:40:40 2014 +0100

----------------------------------------------------------------------
 .../hypervisor/kvm/resource/LibvirtVMDef.java   |  4 +++
 .../resource/LibvirtDomainXMLParserTest.java    | 26 ++++++++++++++------
 2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1baebebd/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index 1e90093..ff75d61 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -836,6 +836,10 @@ public class LibvirtVMDef {
             return _macAddr;
         }
 
+        public nicModel getModel() {
+            return _model;
+        }
+
         public void setVirtualPortType(String virtualPortType) {
             _virtualPortType = virtualPortType;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1baebebd/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
index bbe2f23..c24a8d3 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java
@@ -22,6 +22,7 @@ package com.cloud.hypervisor.kvm.resource;
 import junit.framework.TestCase;
 import java.util.List;
 import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
+import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
 
 public class LibvirtDomainXMLParserTest extends TestCase {
 
@@ -34,6 +35,9 @@ public class LibvirtDomainXMLParserTest extends TestCase {
         DiskDef.diskFmtType diskFormat = DiskDef.diskFmtType.QCOW2;
         DiskDef.diskCacheMode diskCache = DiskDef.diskCacheMode.NONE;
 
+        InterfaceDef.nicModel ifModel = InterfaceDef.nicModel.VIRTIO;
+        InterfaceDef.guestNetType ifType = InterfaceDef.guestNetType.BRIDGE;
+
         String diskLabel ="vda";
         String diskPath = "/var/lib/libvirt/images/my-test-image.qcow2";
 
@@ -96,35 +100,35 @@ public class LibvirtDomainXMLParserTest extends TestCase {
                      "<alias name='virtio-serial0'/>" +
                      "<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>" +
                      "</controller>" +
-                     "<interface type='bridge'>" +
+                     "<interface type='" + ifType.toString() + "'>" +
                      "<mac address='0e:00:a9:fe:02:00'/>" +
                      "<source bridge='cloud0'/>" +
                      "<target dev='vnet0'/>" +
-                     "<model type='virtio'/>" +
+                     "<model type='" + ifModel.toString() + "'/>" +
                      "<alias name='net0'/>" +
                      "<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>" +
                      "</interface>" +
-                     "<interface type='bridge'>" +
+                     "<interface type='" + ifType.toString() + "'>" +
                      "<mac address='06:c5:94:00:05:65'/>" +
                      "<source bridge='cloudbr1'/>" +
                      "<target dev='vnet1'/>" +
-                     "<model type='virtio'/>" +
+                     "<model type='" + ifModel.toString() + "'/>" +
                      "<alias name='net1'/>" +
                      "<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>" +
                      "</interface>" +
-                     "<interface type='bridge'>" +
+                     "<interface type='" + ifType.toString() + "'>" +
                      "<mac address='06:c9:f4:00:04:40'/>" +
                      "<source bridge='cloudbr0'/>" +
                      "<target dev='vnet2'/>" +
-                     "<model type='virtio'/>" +
+                     "<model type='" + ifModel.toString() + "'/>" +
                      "<alias name='net2'/>" +
                      "<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>" +
                      "</interface>" +
-                     "<interface type='bridge'>" +
+                     "<interface type='" + ifType.toString() + "'>" +
                      "<mac address='06:7e:c6:00:05:68'/>" +
                      "<source bridge='cloudbr1'/>" +
                      "<target dev='vnet3'/>" +
-                     "<model type='virtio'/>" +
+                     "<model type='" + ifModel.toString() + "'/>" +
                      "<alias name='net3'/>" +
                      "<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>" +
                      "</interface>" +
@@ -180,5 +184,11 @@ public class LibvirtDomainXMLParserTest extends TestCase {
         assertEquals(diskType, disks.get(diskId).getDiskType());
         assertEquals(deviceType, disks.get(diskId).getDeviceType());
         assertEquals(diskFormat, disks.get(diskId).getDiskFormatType());
+
+        List<InterfaceDef> ifs = parser.getInterfaces();
+        for (int i = 0; i < ifs.size(); i++) {
+            assertEquals(ifModel, ifs.get(i).getModel());
+            assertEquals(ifType, ifs.get(i).getNetType());
+        }
     }
 }
\ No newline at end of file


[45/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6046:CreateVolume from snapshot is failing with S3 as
secondary storage and zone-wide primary storage.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/62127671
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/62127671
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/62127671

Branch: refs/heads/rbac
Commit: 621276715afbe27c861bfa8ee4bf0a96bd202106
Parents: 782c530
Author: Min Chen <mi...@citrix.com>
Authored: Thu Feb 6 15:33:05 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Thu Feb 6 15:36:26 2014 -0800

----------------------------------------------------------------------
 .../cloudstack/storage/motion/AncientDataMotionStrategy.java      | 2 +-
 .../cloudstack/storage/endpoint/DefaultEndPointSelector.java      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62127671/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index fa1dce4..7ae793f 100644
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -242,7 +242,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
             if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
                 ep = selector.select(volObj);
             } else {
-                ep = selector.select(snapObj, volObj);
+                ep = selector.select(srcData, volObj);
             }
 
             CopyCommand cmd = new CopyCommand(srcData.getTO(), volObj.getTO(), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62127671/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index 51c04bf..d64f755 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -166,10 +166,11 @@ public class DefaultEndPointSelector implements EndPointSelector {
             poolId = destStore.getId();
         } else {
             // if both are zone scope
-            selectedScope = srcScope;
             if (srcStore.getRole() == DataStoreRole.Primary) {
+                selectedScope = srcScope;
                 poolId = srcStore.getId();
             } else if (destStore.getRole() == DataStoreRole.Primary) {
+                selectedScope = destScope;
                 poolId = destStore.getId();
             }
         }


[21/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
NetworkManager Exception Fix Due to call to getDhcpServiceProvider()

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6523c068
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6523c068
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6523c068

Branch: refs/heads/rbac
Commit: 6523c068695d0431070060667c222eb40d54b14d
Parents: 884c03f
Author: Soheil Eizadi <se...@infoblox.com>
Authored: Wed Feb 5 17:14:05 2014 +0100
Committer: Daan Hoogland <da...@onecht.net>
Committed: Wed Feb 5 17:14:05 2014 +0100

----------------------------------------------------------------------
 .../orchestration/NetworkOrchestrator.java      | 21 ++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6523c068/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 85fa530..ce40762 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -1539,7 +1539,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         }
 
         // remove the dhcpservice ip if this is the last nic in subnet.
-        if (vm.getType() == Type.User && isDhcpAccrossMultipleSubnetsSupported(network) && isLastNicInSubnet(nic) && network.getTrafficType() == TrafficType.Guest
+        DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
+        if (dhcpServiceProvider != null
+                && vm.getType() == Type.User
+                && isDhcpAccrossMultipleSubnetsSupported(dhcpServiceProvider)
+                && isLastNicInSubnet(nic)
+                && network.getTrafficType() == TrafficType.Guest
                 && network.getGuestType() == GuestType.Shared) {
             removeDhcpServiceInSubnet(nic);
         }
@@ -1553,12 +1558,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         }
     }
 
-    public boolean isDhcpAccrossMultipleSubnetsSupported(Network network) {
-        if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)) {
-            return false;
-        }
+    public boolean isDhcpAccrossMultipleSubnetsSupported(DhcpServiceProvider dhcpServiceProvider) {
 
-        DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
         Map<Network.Capability, String> capabilities = dhcpServiceProvider.getCapabilities().get(Network.Service.Dhcp);
         String supportsMultipleSubnets = capabilities.get(Network.Capability.DhcpAccrossMultipleSubnets);
         if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) {
@@ -2429,8 +2430,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
             return null;
         }
 
-        return (DhcpServiceProvider)_networkModel.getElementImplementingProvider(DhcpProvider);
-
+        NetworkElement element = _networkModel.getElementImplementingProvider(DhcpProvider);
+        if ( element instanceof DhcpServiceProvider ) {
+            return (DhcpServiceProvider)_networkModel.getElementImplementingProvider(DhcpProvider);
+        } else {
+            return null;
+        }
     }
 
     protected boolean isSharedNetworkWithServices(Network network) {


[18/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Every tar has it's own way of doing things


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/28ac2f75
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/28ac2f75
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/28ac2f75

Branch: refs/heads/rbac
Commit: 28ac2f758ea85cf315c98d5ef121b6e20bfe6ddf
Parents: 3df97bd
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 11:48:53 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 11:48:53 2014 +0100

----------------------------------------------------------------------
 tools/appliance/definitions/systemvm64template/postinstall.sh | 2 +-
 tools/appliance/definitions/systemvmtemplate/postinstall.sh   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/28ac2f75/tools/appliance/definitions/systemvm64template/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvm64template/postinstall.sh b/tools/appliance/definitions/systemvm64template/postinstall.sh
index a9e0b89..cc8ead9 100644
--- a/tools/appliance/definitions/systemvm64template/postinstall.sh
+++ b/tools/appliance/definitions/systemvm64template/postinstall.sh
@@ -221,7 +221,7 @@ configure_services() {
   snapshot_dir="/opt/cloudstack*"
   cd /opt
   wget --no-check-certificate $snapshot_url -O cloudstack.tar.gz
-  tar -zxvf cloudstack.tar.gz 'cloudstack-HEAD-???????/systemvm'
+  tar -zxvf cloudstack.tar.gz --wildcards 'cloudstack-HEAD-???????/systemvm'
   cp -rv $snapshot_dir/systemvm/patches/debian/config/* /
   cp -rv $snapshot_dir/systemvm/patches/debian/vpn/* /
   mkdir -p /usr/share/cloud/

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/28ac2f75/tools/appliance/definitions/systemvmtemplate/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/postinstall.sh b/tools/appliance/definitions/systemvmtemplate/postinstall.sh
index d613483..23e66dd 100644
--- a/tools/appliance/definitions/systemvmtemplate/postinstall.sh
+++ b/tools/appliance/definitions/systemvmtemplate/postinstall.sh
@@ -211,7 +211,7 @@ configure_services() {
   snapshot_dir="/opt/cloudstack*"
   cd /opt
   wget --no-check-certificate $snapshot_url -O cloudstack.tar.gz
-  tar -zxvf cloudstack.tar.gz 'cloudstack-HEAD-???????/systemvm'
+  tar -zxvf cloudstack.tar.gz --wildcards 'cloudstack-HEAD-???????/systemvm'
   cp -rv $snapshot_dir/systemvm/patches/debian/config/* /
   cp -rv $snapshot_dir/systemvm/patches/debian/vpn/* /
   mkdir -p /usr/share/cloud/


[11/50] [abbrv] Moved the controlling logic for secondary storage vm into place

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
new file mode 100755
index 0000000..4a59d8f
--- /dev/null
+++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
@@ -0,0 +1,1388 @@
+// 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.secondarystorage;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.config.ApiServiceConfiguration;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.utils.identity.ManagementServerNode;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.RebootCommand;
+import com.cloud.agent.api.SecStorageFirewallCfgCommand;
+import com.cloud.agent.api.SecStorageSetupAnswer;
+import com.cloud.agent.api.SecStorageSetupCommand;
+import com.cloud.agent.api.SecStorageVMSetupCommand;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupSecondaryStorageCommand;
+import com.cloud.agent.api.check.CheckSshAnswer;
+import com.cloud.agent.api.check.CheckSshCommand;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.agent.manager.Commands;
+import com.cloud.capacity.dao.CapacityDao;
+import com.cloud.cluster.ClusterManager;
+import com.cloud.configuration.Config;
+import com.cloud.configuration.ZoneConfig;
+import com.cloud.consoleproxy.ConsoleProxyManager;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.deploy.DataCenterDeployment;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.StorageUnavailableException;
+import com.cloud.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.info.RunningHostCountInfo;
+import com.cloud.info.RunningHostInfoAgregator;
+import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.rules.RulesManager;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.resource.ResourceManager;
+import com.cloud.resource.ResourceStateAdapter;
+import com.cloud.resource.ServerResource;
+import com.cloud.resource.UnableDeleteHostException;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.UploadVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.SnapshotDao;
+import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.storage.dao.UploadDao;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.secondary.SecStorageVmAlertEventArgs;
+import com.cloud.storage.secondary.SecondaryStorageListener;
+import com.cloud.storage.secondary.SecondaryStorageVmAllocator;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.storage.template.TemplateConstants;
+import com.cloud.template.TemplateManager;
+import com.cloud.user.Account;
+import com.cloud.user.AccountService;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.QueryBuilder;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.events.SubscriptionMgr;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.Nic;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.SecondaryStorageVm;
+import com.cloud.vm.SecondaryStorageVmVO;
+import com.cloud.vm.SystemVmLoadScanHandler;
+import com.cloud.vm.SystemVmLoadScanner;
+import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachineGuru;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.VirtualMachineName;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.SecondaryStorageVmDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
+import com.cloud.vm.dao.VMInstanceDao;
+
+//
+// Possible secondary storage vm state transition cases
+//        Creating -> Destroyed
+//        Creating -> Stopped --> Starting -> Running
+//        HA -> Stopped -> Starting -> Running
+//        Migrating -> Running    (if previous state is Running before it enters into Migrating state
+//        Migrating -> Stopped    (if previous state is not Running before it enters into Migrating state)
+//        Running -> HA            (if agent lost connection)
+//        Stopped -> Destroyed
+//
+//        Creating state indicates of record creating and IP address allocation are ready, it is a transient
+//         state which will soon be switching towards Running if everything goes well.
+//        Stopped state indicates the readiness of being able to start (has storage and IP resources allocated)
+//        Starting state can only be entered from Stopped states
+//
+// Starting, HA, Migrating, Creating and Running state are all counted as "Open" for available capacity calculation
+// because sooner or later, it will be driven into Running state
+//
+@Local(value = {SecondaryStorageVmManager.class})
+public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager, VirtualMachineGuru, SystemVmLoadScanHandler<Long>,
+        ResourceStateAdapter {
+    private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class);
+
+    private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30
+    // seconds
+    private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC = 180; // 3
+    // minutes
+
+    private static final int STARTUP_DELAY = 60000; // 60 seconds
+
+    private int _mgmtPort = 8250;
+
+    private List<SecondaryStorageVmAllocator> _ssVmAllocators;
+
+    @Inject
+    protected SecondaryStorageVmDao _secStorageVmDao;
+    @Inject
+    private DataCenterDao _dcDao;
+    @Inject
+    private VMTemplateDao _templateDao;
+    @Inject
+    private HostDao _hostDao;
+    @Inject
+    private StoragePoolHostDao _storagePoolHostDao;
+    @Inject
+    private AgentManager _agentMgr;
+    @Inject
+    protected NetworkOrchestrationService _networkMgr;
+    @Inject
+    protected NetworkModel _networkModel;
+    @Inject
+    protected SnapshotDao _snapshotDao;
+    private SecondaryStorageListener _listener;
+
+    private ServiceOfferingVO _serviceOffering;
+
+    @Inject
+    protected ConfigurationDao _configDao;
+    @Inject
+    private ServiceOfferingDao _offeringDao;
+    @Inject
+    private AccountService _accountMgr;
+    @Inject
+    private VirtualMachineManager _itMgr;
+    @Inject
+    protected VMInstanceDao _vmDao;
+    @Inject
+    protected CapacityDao _capacityDao;
+    @Inject
+    UserVmDetailsDao _vmDetailsDao;
+    @Inject
+    protected ResourceManager _resourceMgr;
+    @Inject
+    NetworkDao _networkDao;
+    @Inject
+    NetworkOfferingDao _networkOfferingDao;
+    @Inject
+    protected IPAddressDao _ipAddressDao = null;
+    @Inject
+    protected RulesManager _rulesMgr;
+    @Inject
+    TemplateManager templateMgr;
+    @Inject
+    UploadDao _uploadDao;
+
+    @Inject
+    KeystoreManager _keystoreMgr;
+    @Inject
+    DataStoreManager _dataStoreMgr;
+    @Inject
+    ImageStoreDao _imageStoreDao;
+    @Inject
+    TemplateDataStoreDao _tmplStoreDao;
+    private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
+    private int _secStorageVmMtuSize;
+
+    private String _instance;
+    private boolean _useLocalStorage;
+    private boolean _useSSlCopy;
+    private String _httpProxy;
+    private String _allowedInternalSites;
+    protected long _nodeId = ManagementServerNode.getManagementServerId();
+
+    private SystemVmLoadScanner<Long> _loadScanner;
+    private Map<Long, ZoneHostInfo> _zoneHostInfoMap; // map <zone id, info about running host in zone>
+
+    private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName());
+
+    public SecondaryStorageManagerImpl() {
+    }
+
+    @Override
+    public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) {
+        try {
+            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
+            _itMgr.advanceStart(secStorageVm.getUuid(), null, null);
+            return _secStorageVmDao.findById(secStorageVm.getId());
+        } catch (StorageUnavailableException e) {
+            s_logger.warn("Exception while trying to start secondary storage vm", e);
+            return null;
+        } catch (InsufficientCapacityException e) {
+            s_logger.warn("Exception while trying to start secondary storage vm", e);
+            return null;
+        } catch (ResourceUnavailableException e) {
+            s_logger.warn("Exception while trying to start secondary storage vm", e);
+            return null;
+        } catch (Exception e) {
+            s_logger.warn("Exception while trying to start secondary storage vm", e);
+            return null;
+        }
+    }
+
+    SecondaryStorageVmVO getSSVMfromHost(HostVO ssAHost) {
+        if (ssAHost.getType() == Host.Type.SecondaryStorageVM) {
+            return _secStorageVmDao.findByInstanceName(ssAHost.getName());
+        }
+        return null;
+    }
+
+    @Override
+    public boolean generateSetupCommand(Long ssHostId) {
+        HostVO cssHost = _hostDao.findById(ssHostId);
+        Long zoneId = cssHost.getDataCenterId();
+        if (cssHost.getType() == Host.Type.SecondaryStorageVM) {
+
+            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(cssHost.getName());
+            if (secStorageVm == null) {
+                s_logger.warn("secondary storage VM " + cssHost.getName() + " doesn't exist");
+                return false;
+            }
+
+            List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
+            for (DataStore ssStore : ssStores) {
+                if (!(ssStore.getTO() instanceof NfsTO)) {
+                    continue; // only do this for Nfs
+                }
+                String secUrl = ssStore.getUri();
+                SecStorageSetupCommand setupCmd = null;
+                if (!_useSSlCopy) {
+                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
+                } else {
+                    KeystoreManager.Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
+                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
+                }
+
+                Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
+                if (answer != null && answer.getResult()) {
+                    SecStorageSetupAnswer an = (SecStorageSetupAnswer)answer;
+                    if (an.get_dir() != null) {
+                        // update the parent path in image_store table for this image store
+                        ImageStoreVO svo = _imageStoreDao.findById(ssStore.getId());
+                        svo.setParent(an.get_dir());
+                        _imageStoreDao.update(ssStore.getId(), svo);
+                    }
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
+                    }
+                } else {
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
+                    }
+                    return false;
+                }
+            }
+        }
+        /* After removing SecondaryStorage entries from host table, control should never come here!!
+        else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
+            List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
+            String secUrl = cssHost.getStorageUrl();
+            SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
+            for ( SecondaryStorageVmVO ssVm : alreadyRunning ) {
+                HostVO host = _resourceMgr.findHostByName(ssVm.getInstanceName());
+                Answer answer = _agentMgr.easySend(host.getId(), setupCmd);
+                if (answer != null && answer.getResult()) {
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
+                    }
+                } else {
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
+                    }
+                    return false;
+                }
+            }
+        }
+         */
+        return true;
+    }
+
+    @Override
+    public boolean generateVMSetupCommand(Long ssAHostId) {
+        HostVO ssAHost = _hostDao.findById(ssAHostId);
+        if (ssAHost.getType() != Host.Type.SecondaryStorageVM) {
+            return false;
+        }
+        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
+        if (secStorageVm == null) {
+            s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
+            return false;
+        }
+
+        SecStorageVMSetupCommand setupCmd = new SecStorageVMSetupCommand();
+        if (_allowedInternalSites != null) {
+            List<String> allowedCidrs = new ArrayList<String>();
+            String[] cidrs = _allowedInternalSites.split(",");
+            for (String cidr : cidrs) {
+                if (NetUtils.isValidCIDR(cidr) || NetUtils.isValidIp(cidr) || !cidr.startsWith("0.0.0.0")) {
+                    allowedCidrs.add(cidr);
+                }
+            }
+            List<? extends Nic> nics = _networkModel.getNicsForTraffic(secStorageVm.getId(), TrafficType.Management);
+            setupCmd.setAllowedInternalSites(allowedCidrs.toArray(new String[allowedCidrs.size()]));
+        }
+        String copyPasswd = _configDao.getValue("secstorage.copy.password");
+        setupCmd.setCopyPassword(copyPasswd);
+        setupCmd.setCopyUserName(TemplateConstants.DEFAULT_HTTP_AUTH_USER);
+        Answer answer = _agentMgr.easySend(ssAHostId, setupCmd);
+        if (answer != null && answer.getResult()) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Successfully programmed http auth into " + secStorageVm.getHostName());
+            }
+            return true;
+        } else {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("failed to program http auth into secondary storage vm : " + secStorageVm.getHostName());
+            }
+            return false;
+        }
+    }
+
+    @Override
+    public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
+        return null;
+    }
+
+    @Override
+    public boolean generateFirewallConfiguration(Long ssAHostId) {
+        if (ssAHostId == null) {
+            return true;
+        }
+        HostVO ssAHost = _hostDao.findById(ssAHostId);
+        SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
+
+        if (thisSecStorageVm == null) {
+            s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
+            return false;
+        }
+
+        String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
+        SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
+        thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
+
+        QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
+        sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
+        sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
+        List<HostVO> ssvms = sc.list();
+        for (HostVO ssvm : ssvms) {
+            if (ssvm.getId() == ssAHostId) {
+                continue;
+            }
+            Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
+            if (answer != null && answer.getResult()) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
+                }
+            } else {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
+                }
+                return false;
+            }
+        }
+
+        SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
+        for (HostVO ssvm : ssvms) {
+            if (ssvm.getId() == ssAHostId) {
+                continue;
+            }
+            allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
+        }
+
+        Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
+        if (answer != null && answer.getResult()) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
+            }
+        } else {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
+            }
+            return false;
+        }
+
+        return true;
+
+    }
+
+    protected boolean isSecondaryStorageVmRequired(long dcId) {
+        DataCenterVO dc = _dcDao.findById(dcId);
+        _dcDao.loadDetails(dc);
+        String ssvmReq = dc.getDetail(ZoneConfig.EnableSecStorageVm.key());
+        if (ssvmReq != null) {
+            return Boolean.parseBoolean(ssvmReq);
+        }
+        return true;
+    }
+
+    public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role role) {
+
+        if (!isSecondaryStorageVmRequired(dataCenterId)) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
+            }
+            return null;
+        }
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Assign secondary storage vm from a newly started instance for request from data center : " + dataCenterId);
+        }
+
+        Map<String, Object> context = createSecStorageVmInstance(dataCenterId, role);
+
+        long secStorageVmId = (Long)context.get("secStorageVmId");
+        if (secStorageVmId == 0) {
+            if (s_logger.isTraceEnabled()) {
+                s_logger.trace("Creating secondary storage vm instance failed, data center id : " + dataCenterId);
+            }
+
+            return null;
+        }
+
+        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
+        // SecondaryStorageVmVO secStorageVm =
+        // allocSecStorageVmStorage(dataCenterId, secStorageVmId);
+        if (secStorageVm != null) {
+            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
+                new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATED, dataCenterId, secStorageVmId, secStorageVm, null));
+            return secStorageVm;
+        } else {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: " +
+                    secStorageVmId);
+            }
+
+            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
+                new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage"));
+        }
+        return null;
+    }
+
+    protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, SecondaryStorageVm.Role role) {
+        DataStore secStore = _dataStoreMgr.getImageStore(dataCenterId);
+        if (secStore == null) {
+            String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
+            s_logger.warn(msg);
+            throw new CloudRuntimeException(msg);
+        }
+
+        long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
+        String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
+        Account systemAcct = _accountMgr.getSystemAccount();
+
+        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
+        DataCenter dc = _dcDao.findById(plan.getDataCenterId());
+
+        NetworkVO defaultNetwork = null;
+        if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
+            List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
+            if (networks == null || networks.size() == 0) {
+                throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
+            }
+            defaultNetwork = networks.get(0);
+        } else {
+            TrafficType defaultTrafficType = TrafficType.Public;
+
+            if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
+                defaultTrafficType = TrafficType.Guest;
+            }
+            List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
+            // api should never allow this situation to happen
+            if (defaultNetworks.size() != 1) {
+                throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
+            }
+            defaultNetwork = defaultNetworks.get(0);
+        }
+
+        List<? extends NetworkOffering> offerings =
+            _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork,
+                NetworkOffering.SystemStorageNetwork);
+        LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(offerings.size() + 1);
+        NicProfile defaultNic = new NicProfile();
+        defaultNic.setDefaultNic(true);
+        defaultNic.setDeviceId(2);
+        try {
+            networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0),
+                defaultNic);
+            for (NetworkOffering offering : offerings) {
+                networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null);
+            }
+        } catch (ConcurrentOperationException e) {
+            s_logger.info("Unable to setup due to concurrent operation. " + e);
+            return new HashMap<String, Object>();
+        }
+
+        VMTemplateVO template = null;
+        HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
+        template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
+        if (template == null) {
+            throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
+        }
+
+        SecondaryStorageVmVO secStorageVm =
+            new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
+                systemAcct.getDomainId(), systemAcct.getId(), role, _serviceOffering.getOfferHA());
+        secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
+        secStorageVm = _secStorageVmDao.persist(secStorageVm);
+        try {
+            _itMgr.allocate(name, template, _serviceOffering, networks, plan, null);
+            secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
+        } catch (InsufficientCapacityException e) {
+            s_logger.warn("InsufficientCapacity", e);
+            throw new CloudRuntimeException("Insufficient capacity exception", e);
+        }
+
+        Map<String, Object> context = new HashMap<String, Object>();
+        context.put("secStorageVmId", secStorageVm.getId());
+        return context;
+    }
+
+    private SecondaryStorageVmAllocator getCurrentAllocator() {
+
+        // for now, only one adapter is supported
+        if (_ssVmAllocators.size() > 0) {
+            return _ssVmAllocators.get(0);
+        }
+
+        return null;
+    }
+
+    protected String connect(String ipAddress, int port) {
+        return null;
+    }
+
+    public SecondaryStorageVmVO assignSecStorageVmFromRunningPool(long dataCenterId, SecondaryStorageVm.Role role) {
+
+        if (s_logger.isTraceEnabled()) {
+            s_logger.trace("Assign  secondary storage vm from running pool for request from data center : " + dataCenterId);
+        }
+
+        SecondaryStorageVmAllocator allocator = getCurrentAllocator();
+        assert (allocator != null);
+        List<SecondaryStorageVmVO> runningList = _secStorageVmDao.getSecStorageVmListInStates(role, dataCenterId, State.Running);
+        if (runningList != null && runningList.size() > 0) {
+            if (s_logger.isTraceEnabled()) {
+                s_logger.trace("Running secondary storage vm pool size : " + runningList.size());
+                for (SecondaryStorageVmVO secStorageVm : runningList) {
+                    s_logger.trace("Running secStorageVm instance : " + secStorageVm.getHostName());
+                }
+            }
+
+            Map<Long, Integer> loadInfo = new HashMap<Long, Integer>();
+
+            return allocator.allocSecondaryStorageVm(runningList, loadInfo, dataCenterId);
+        } else {
+            if (s_logger.isTraceEnabled()) {
+                s_logger.trace("Empty running secStorageVm pool for now in data center : " + dataCenterId);
+            }
+        }
+        return null;
+    }
+
+    public SecondaryStorageVmVO assignSecStorageVmFromStoppedPool(long dataCenterId, SecondaryStorageVm.Role role) {
+        List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates(role, dataCenterId, State.Starting, State.Stopped, State.Migrating);
+        if (l != null && l.size() > 0) {
+            return l.get(0);
+        }
+
+        return null;
+    }
+
+    private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
+        if (s_logger.isTraceEnabled()) {
+            s_logger.trace("Allocate secondary storage vm standby capacity for data center : " + dataCenterId);
+        }
+
+        if (!isSecondaryStorageVmRequired(dataCenterId)) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
+            }
+            return;
+        }
+
+        boolean secStorageVmFromStoppedPool = false;
+        SecondaryStorageVmVO secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
+        if (secStorageVm == null) {
+            if (s_logger.isInfoEnabled()) {
+                s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm");
+            }
+
+            if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
+                try {
+                    secStorageVm = startNew(dataCenterId, role);
+                    for (UploadVO upload : _uploadDao.listAll()) {
+                        _uploadDao.expunge(upload.getId());
+                    }
+                } finally {
+                    _allocLock.unlock();
+                }
+            } else {
+                if (s_logger.isInfoEnabled()) {
+                    s_logger.info("Unable to acquire synchronization lock to allocate secStorageVm resource for standby capacity, wait for next scan");
+                }
+                return;
+            }
+        } else {
+            if (s_logger.isInfoEnabled()) {
+                s_logger.info("Found a stopped secondary storage vm, bring it up to running pool. secStorageVm vm id : " + secStorageVm.getId());
+            }
+            secStorageVmFromStoppedPool = true;
+        }
+
+        if (secStorageVm != null) {
+            long secStorageVmId = secStorageVm.getId();
+            GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
+            try {
+                if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
+                    try {
+                        secStorageVm = startSecStorageVm(secStorageVmId);
+                    } finally {
+                        secStorageVmLock.unlock();
+                    }
+                } else {
+                    if (s_logger.isInfoEnabled()) {
+                        s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId());
+                    }
+                    return;
+                }
+            } finally {
+                secStorageVmLock.releaseRef();
+            }
+
+            if (secStorageVm == null) {
+                if (s_logger.isInfoEnabled()) {
+                    s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId +
+                        ", will recycle it and start a new one");
+                }
+
+                if (secStorageVmFromStoppedPool) {
+                    destroySecStorageVm(secStorageVmId);
+                }
+            } else {
+                if (s_logger.isInfoEnabled()) {
+                    s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
+                }
+            }
+        }
+    }
+
+    public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
+        ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
+        if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) {
+            VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
+            if (template == null) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
+                }
+                return false;
+            }
+
+            List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
+            if (stores.size() < 1) {
+                s_logger.debug("No image store added  in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
+                return false;
+            }
+
+            DataStore store = templateMgr.getImageStore(dataCenterId, template.getId());
+            if (store == null) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("No secondary storage available in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
+                }
+                return false;
+            }
+
+            List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !_useLocalStorage);
+            if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
+                return true;
+            } else {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Primary storage is not ready, wait until it is ready to launch secondary storage vm. dcId: " + dataCenterId +
+                        " system.vm.use.local.storage: " + _useLocalStorage +
+                        "If you want to use local storage to start ssvm, need to set system.vm.use.local.storage to true");
+                }
+            }
+
+        }
+        return false;
+    }
+
+    private synchronized Map<Long, ZoneHostInfo> getZoneHostInfo() {
+        Date cutTime = DateUtil.currentGMTTime();
+        List<RunningHostCountInfo> l = _hostDao.getRunningHostCounts(new Date(cutTime.getTime() - ClusterManager.HeartbeatThreshold.value()));
+
+        RunningHostInfoAgregator aggregator = new RunningHostInfoAgregator();
+        if (l.size() > 0) {
+            for (RunningHostCountInfo countInfo : l) {
+                aggregator.aggregate(countInfo);
+            }
+        }
+
+        return aggregator.getZoneHostInfoMap();
+    }
+
+    @Override
+    public boolean start() {
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Start secondary storage vm manager");
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        _loadScanner.stop();
+        _allocLock.releaseRef();
+        _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
+        return true;
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Start configuring secondary storage vm manager : " + name);
+        }
+
+        Map<String, String> configs = _configDao.getConfiguration("management-server", params);
+
+        _secStorageVmMtuSize = NumbersUtil.parseInt(configs.get("secstorage.vm.mtu.size"), DEFAULT_SS_VM_MTUSIZE);
+        String useServiceVM = _configDao.getValue("secondary.storage.vm");
+        boolean _useServiceVM = false;
+        if ("true".equalsIgnoreCase(useServiceVM)) {
+            _useServiceVM = true;
+        }
+
+        String sslcopy = _configDao.getValue("secstorage.encrypt.copy");
+        if ("true".equalsIgnoreCase(sslcopy)) {
+            _useSSlCopy = true;
+        }
+
+        _allowedInternalSites = _configDao.getValue("secstorage.allowed.internal.sites");
+
+        String value = configs.get("secstorage.capacityscan.interval");
+        _capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL);
+
+        _instance = configs.get("instance.name");
+        if (_instance == null) {
+            _instance = "DEFAULT";
+        }
+
+        Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
+
+        value = agentMgrConfigs.get("port");
+        _mgmtPort = NumbersUtil.parseInt(value, 8250);
+
+        _listener = new SecondaryStorageListener(this);
+        _agentMgr.registerForHostEvents(_listener, true, false, true);
+
+        _itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);
+
+        //check if there is a default service offering configured
+        String ssvmSrvcOffIdStr = configs.get(Config.SecondaryStorageServiceOffering.key());
+        if (ssvmSrvcOffIdStr != null) {
+            Long ssvmSrvcOffId = Long.parseLong(ssvmSrvcOffIdStr);
+            _serviceOffering = _offeringDao.findById(ssvmSrvcOffId);
+            if (_serviceOffering == null || !_serviceOffering.getSystemUse()) {
+                String msg = "Can't find system service offering id=" + ssvmSrvcOffId + " for secondary storage vm";
+                s_logger.error(msg);
+                throw new ConfigurationException(msg);
+            }
+        } else {
+            int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE);
+            int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ);
+            _useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
+            _serviceOffering =
+                new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, ramSize, cpuFreq, null, null, false, null, _useLocalStorage, true, null, true,
+                    VirtualMachine.Type.SecondaryStorageVm, true);
+            _serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName);
+            _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
+
+            // this can sometimes happen, if DB is manually or programmatically manipulated
+            if (_serviceOffering == null) {
+                String msg = "Data integrity problem : System Offering For Secondary Storage VM has been removed?";
+                s_logger.error(msg);
+                throw new ConfigurationException(msg);
+            }
+        }
+
+        if (_useServiceVM) {
+            _loadScanner = new SystemVmLoadScanner<Long>(this);
+            _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval);
+        }
+
+        _httpProxy = configs.get(Config.SecStorageProxy.key());
+        if (_httpProxy != null) {
+            boolean valid = true;
+            String errMsg = null;
+            try {
+                URI uri = new URI(_httpProxy);
+                if (!"http".equalsIgnoreCase(uri.getScheme())) {
+                    errMsg = "Only support http proxy";
+                    valid = false;
+                } else if (uri.getHost() == null) {
+                    errMsg = "host can not be null";
+                    valid = false;
+                } else if (uri.getPort() == -1) {
+                    _httpProxy = _httpProxy + ":3128";
+                }
+            } catch (URISyntaxException e) {
+                errMsg = e.toString();
+            } finally {
+                if (!valid) {
+                    s_logger.debug("ssvm http proxy " + _httpProxy + " is invalid: " + errMsg);
+                    throw new ConfigurationException("ssvm http proxy " + _httpProxy + "is invalid: " + errMsg);
+                }
+            }
+        }
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Secondary storage vm Manager is configured.");
+        }
+        _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
+        return true;
+    }
+
+    @Override
+    public boolean stopSecStorageVm(long secStorageVmId) {
+        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
+        if (secStorageVm == null) {
+            String msg = "Stopping secondary storage vm failed: secondary storage vm " + secStorageVmId + " no longer exists";
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug(msg);
+            }
+            return false;
+        }
+        try {
+            if (secStorageVm.getHostId() != null) {
+                GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
+                try {
+                    if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
+                        try {
+                            _itMgr.stop(secStorageVm.getUuid());
+                            return true;
+                        } finally {
+                            secStorageVmLock.unlock();
+                        }
+                    } else {
+                        String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
+                        s_logger.debug(msg);
+                        return false;
+                    }
+                } finally {
+                    secStorageVmLock.releaseRef();
+                }
+            }
+
+            // vm was already stopped, return true
+            return true;
+        } catch (ResourceUnavailableException e) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Stopping secondary storage vm " + secStorageVm.getHostName() + " faled : exception " + e.toString());
+            }
+            return false;
+        }
+    }
+
+    @Override
+    public boolean rebootSecStorageVm(long secStorageVmId) {
+        final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
+
+        if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
+            return false;
+        }
+
+        if (secStorageVm.getState() == State.Running && secStorageVm.getHostId() != null) {
+            final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName());
+            final Answer answer = _agentMgr.easySend(secStorageVm.getHostId(), cmd);
+
+            if (answer != null && answer.getResult()) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
+                }
+
+                SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
+                    new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
+
+                return true;
+            } else {
+                String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug(msg);
+                }
+                return false;
+            }
+        } else {
+            return startSecStorageVm(secStorageVmId) != null;
+        }
+    }
+
+    @Override
+    public boolean destroySecStorageVm(long vmId) {
+        SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
+
+        try {
+            _itMgr.expunge(ssvm.getUuid());
+            _secStorageVmDao.remove(ssvm.getId());
+            HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(), Host.Type.SecondaryStorageVM);
+            if (host != null) {
+                s_logger.debug("Removing host entry for ssvm id=" + vmId);
+                _hostDao.remove(host.getId());
+            }
+
+            return true;
+        } catch (ResourceUnavailableException e) {
+            s_logger.warn("Unable to expunge " + ssvm, e);
+            return false;
+        }
+    }
+
+    @Override
+    public void onAgentConnect(Long dcId, StartupCommand cmd) {
+    }
+
+    private String getAllocLockName() {
+        // to improve security, it may be better to return a unique mashed
+        // name(for example MD5 hashed)
+        return "secStorageVm.alloc";
+    }
+
+    private String getSecStorageVmLockName(long id) {
+        return "secStorageVm." + id;
+    }
+
+    @Override
+    public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
+
+        SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId());
+        Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
+        vm.setDetails(details);
+
+        DataStore secStore = _dataStoreMgr.getImageStore(dest.getDataCenter().getId());
+        assert (secStore != null);
+
+        StringBuilder buf = profile.getBootArgsBuilder();
+        buf.append(" template=domP type=secstorage");
+        buf.append(" host=").append(ApiServiceConfiguration.ManagementHostIPAdr.value());
+        buf.append(" port=").append(_mgmtPort);
+        buf.append(" name=").append(profile.getVirtualMachine().getHostName());
+
+        buf.append(" zone=").append(dest.getDataCenter().getId());
+        buf.append(" pod=").append(dest.getPod().getId());
+
+        buf.append(" guid=").append(profile.getVirtualMachine().getHostName());
+
+        if (_configDao.isPremium()) {
+            s_logger.debug("VmWare hypervisor configured, telling the ssvm to load the PremiumSecondaryStorageResource");
+            buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource");
+        } else {
+            buf.append(" resource=org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource");
+        }
+        buf.append(" instance=SecStorage");
+        buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy));
+        buf.append(" role=").append(vm.getRole().toString());
+        buf.append(" mtu=").append(_secStorageVmMtuSize);
+
+        boolean externalDhcp = false;
+        String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
+        if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
+            externalDhcp = true;
+        }
+
+        if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
+            buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
+        }
+
+        for (NicProfile nic : profile.getNics()) {
+            int deviceId = nic.getDeviceId();
+            if (nic.getIp4Address() == null) {
+                buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0");
+                buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
+            } else {
+                buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
+                buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
+            }
+
+            if (nic.isDefaultNic()) {
+                buf.append(" gateway=").append(nic.getGateway());
+            }
+            if (nic.getTrafficType() == TrafficType.Management) {
+                String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key());
+                if (NetUtils.isValidCIDR(mgmt_cidr)) {
+                    buf.append(" mgmtcidr=").append(mgmt_cidr);
+                }
+                buf.append(" localgw=").append(dest.getPod().getGateway());
+                buf.append(" private.network.device=").append("eth").append(deviceId);
+            } else if (nic.getTrafficType() == TrafficType.Public) {
+                buf.append(" public.network.device=").append("eth").append(deviceId);
+            } else if (nic.getTrafficType() == TrafficType.Storage) {
+                buf.append(" storageip=").append(nic.getIp4Address());
+                buf.append(" storagenetmask=").append(nic.getNetmask());
+                buf.append(" storagegateway=").append(nic.getGateway());
+            }
+        }
+
+        /* External DHCP mode */
+        if (externalDhcp) {
+            buf.append(" bootproto=dhcp");
+        }
+
+        DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
+        buf.append(" internaldns1=").append(dc.getInternalDns1());
+        if (dc.getInternalDns2() != null) {
+            buf.append(" internaldns2=").append(dc.getInternalDns2());
+        }
+        buf.append(" dns1=").append(dc.getDns1());
+        if (dc.getDns2() != null) {
+            buf.append(" dns2=").append(dc.getDns2());
+        }
+
+        String bootArgs = buf.toString();
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
+
+        finalizeCommandsOnStart(cmds, profile);
+
+        SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
+        DataCenter dc = dest.getDataCenter();
+        List<NicProfile> nics = profile.getNics();
+        for (NicProfile nic : nics) {
+            if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) ||
+                (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
+                secVm.setPublicIpAddress(nic.getIp4Address());
+                secVm.setPublicNetmask(nic.getNetmask());
+                secVm.setPublicMacAddress(nic.getMacAddress());
+            } else if (nic.getTrafficType() == TrafficType.Management) {
+                secVm.setPrivateIpAddress(nic.getIp4Address());
+                secVm.setPrivateMacAddress(nic.getMacAddress());
+            }
+        }
+        _secStorageVmDao.update(secVm.getId(), secVm);
+        return true;
+    }
+
+    @Override
+    public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) {
+
+        NicProfile managementNic = null;
+        NicProfile controlNic = null;
+        for (NicProfile nic : profile.getNics()) {
+            if (nic.getTrafficType() == TrafficType.Management) {
+                managementNic = nic;
+            } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
+                controlNic = nic;
+            }
+        }
+
+        if (controlNic == null) {
+            if (managementNic == null) {
+                s_logger.error("Management network doesn't exist for the secondaryStorageVm " + profile.getVirtualMachine());
+                return false;
+            }
+            controlNic = managementNic;
+        }
+
+        // verify ssh access on management nic for system vm running on HyperV
+        if(profile.getHypervisorType() == HypervisorType.Hyperv) {
+            controlNic = managementNic;
+        }
+
+        CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922);
+        cmds.addCommand("checkSsh", check);
+
+        return true;
+    }
+
+    @Override
+    public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) {
+        CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh");
+        if (!answer.getResult()) {
+            s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
+            return false;
+        }
+
+        try {
+            //get system ip and create static nat rule for the vm in case of basic networking with EIP/ELB
+            _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
+            IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId());
+            if (ipaddr != null && ipaddr.getSystem()) {
+                SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
+                // override SSVM guest IP with EIP, so that download url's with be prepared with EIP
+                secVm.setPublicIpAddress(ipaddr.getAddress().addr());
+                _secStorageVmDao.update(secVm.getId(), secVm);
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
+        //release elastic IP here
+        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
+        if (ip != null && ip.getSystem()) {
+            CallContext ctx = CallContext.current();
+            try {
+                _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
+            } catch (Exception ex) {
+                s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ",
+                    ex);
+            }
+        }
+    }
+
+    @Override
+    public void finalizeExpunge(VirtualMachine vm) {
+        SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid());
+
+        ssvm.setPublicIpAddress(null);
+        ssvm.setPublicMacAddress(null);
+        ssvm.setPublicNetmask(null);
+        _secStorageVmDao.update(ssvm.getId(), ssvm);
+    }
+
+    @Override
+    public String getScanHandlerName() {
+        return "secstorage";
+    }
+
+    @Override
+    public boolean canScan() {
+        return true;
+    }
+
+    @Override
+    public void onScanStart() {
+        _zoneHostInfoMap = getZoneHostInfo();
+    }
+
+    @Override
+    public Long[] getScannablePools() {
+        List<DataCenterVO> zones = _dcDao.listEnabledZones();
+
+        Long[] dcIdList = new Long[zones.size()];
+        int i = 0;
+        for (DataCenterVO dc : zones) {
+            dcIdList[i++] = dc.getId();
+        }
+
+        return dcIdList;
+    }
+
+    @Override
+    public boolean isPoolReadyForScan(Long pool) {
+        // pool is at zone basis
+        long dataCenterId = pool.longValue();
+
+        if (!isZoneReady(_zoneHostInfoMap, dataCenterId)) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Zone " + dataCenterId + " is not ready to launch secondary storage VM yet");
+            }
+            return false;
+        }
+
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Zone " + dataCenterId + " is ready to launch secondary storage VM");
+        }
+        return true;
+    }
+
+    @Override
+    public Pair<AfterScanAction, Object> scanPool(Long pool) {
+        long dataCenterId = pool.longValue();
+
+        List<SecondaryStorageVmVO> ssVms =
+            _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting,
+                State.Stopped, State.Stopping);
+        int vmSize = (ssVms == null) ? 0 : ssVms.size();
+        List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
+        int storeSize = (ssStores == null) ? 0 : ssStores.size();
+        if (storeSize > vmSize) {
+            s_logger.info("No secondary storage vms found in datacenter id=" + dataCenterId + ", starting a new one");
+            return new Pair<AfterScanAction, Object>(AfterScanAction.expand, SecondaryStorageVm.Role.templateProcessor);
+        }
+
+        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, SecondaryStorageVm.Role.templateProcessor);
+    }
+
+    @Override
+    public void expandPool(Long pool, Object actionArgs) {
+        long dataCenterId = pool.longValue();
+        allocCapacity(dataCenterId, (SecondaryStorageVm.Role)actionArgs);
+    }
+
+    @Override
+    public void shrinkPool(Long pool, Object actionArgs) {
+    }
+
+    @Override
+    public void onScanEnd() {
+    }
+
+    @Override
+    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
+        /* Called when Secondary Storage VM connected */
+        StartupCommand firstCmd = cmd[0];
+        if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
+            return null;
+        }
+
+        host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
+        return host;
+    }
+
+    @Override
+    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
+        // Used to be Called when add secondary storage on UI through DummySecondaryStorageResource to update that host entry for Secondary Storage.
+        // Now since we move secondary storage from host table, this code is not needed to be invoked anymore.
+        /*
+        StartupCommand firstCmd = startup[0];
+        if (!(firstCmd instanceof StartupStorageCommand)) {
+            return null;
+        }
+
+        com.cloud.host.Host.Type type = null;
+        StartupStorageCommand ssCmd = ((StartupStorageCommand) firstCmd);
+        if (ssCmd.getHostType() == Host.Type.SecondaryStorageCmdExecutor) {
+            type = ssCmd.getHostType();
+        } else {
+            if (ssCmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) {
+                type = Host.Type.SecondaryStorage;
+                if (resource != null && resource instanceof DummySecondaryStorageResource) {
+                    host.setResource(null);
+                }
+            } else if (ssCmd.getResourceType() == Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE) {
+                type = Host.Type.LocalSecondaryStorage;
+            } else {
+                type = Host.Type.Storage;
+            }
+
+            final Map<String, String> hostDetails = ssCmd.getHostDetails();
+            if (hostDetails != null) {
+                if (details != null) {
+                    details.putAll(hostDetails);
+                } else {
+                    details = hostDetails;
+                }
+            }
+
+            host.setDetails(details);
+            host.setParent(ssCmd.getParent());
+            host.setTotalSize(ssCmd.getTotalSize());
+            host.setHypervisorType(HypervisorType.None);
+            host.setType(type);
+            if (ssCmd.getNfsShare() != null) {
+                host.setStorageUrl(ssCmd.getNfsShare());
+            }
+        }
+         */
+        return null; // no need to handle this event anymore since secondary storage is not in host table anymore.
+    }
+
+    @Override
+    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
+        // Since secondary storage is moved out of host table, this class should not handle delete secondary storage anymore.
+        return null;
+    }
+
+    @Override
+    public List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
+        QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
+        if (dcId != null) {
+            sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId);
+        }
+        sc.and(sc.entity().getState(), Op.IN, Status.Up, Status.Connecting);
+        sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
+        return sc.list();
+    }
+
+    @Override
+    public HostVO pickSsvmHost(HostVO ssHost) {
+        if (ssHost.getType() == Host.Type.LocalSecondaryStorage) {
+            return ssHost;
+        } else if (ssHost.getType() == Host.Type.SecondaryStorage) {
+            Long dcId = ssHost.getDataCenterId();
+            List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
+            if (ssAHosts == null || ssAHosts.isEmpty()) {
+                return null;
+            }
+            Collections.shuffle(ssAHosts);
+            return ssAHosts.get(0);
+        }
+        return null;
+    }
+
+    @Override
+    public void prepareStop(VirtualMachineProfile profile) {
+
+    }
+
+    public List<SecondaryStorageVmAllocator> getSecondaryStorageVmAllocators() {
+        return _ssVmAllocators;
+    }
+
+    @Inject
+    public void setSecondaryStorageVmAllocators(List<SecondaryStorageVmAllocator> ssVmAllocators) {
+        _ssVmAllocators = ssVmAllocators;
+    }
+}


[48/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Slightly improve the error message to make it clean what the problem actually is


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b6db18fa
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b6db18fa
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b6db18fa

Branch: refs/heads/rbac
Commit: b6db18fae4b13d1c54896d2cc13fa3c04d3e6d51
Parents: bac2c1e
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Fri Feb 7 14:10:02 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Fri Feb 7 14:10:02 2014 +0100

----------------------------------------------------------------------
 .../network/router/VirtualNetworkApplianceManagerImpl.java   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b6db18fa/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 6b81cfa..734fc5b 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -42,6 +42,8 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd;
@@ -56,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
@@ -2795,7 +2796,7 @@ Listener, Configurable {
 
     @Override
     public DomainRouterVO stop(final VirtualRouter router, final boolean forced, final User user, final Account caller) throws ConcurrentOperationException,
-            ResourceUnavailableException {
+    ResourceUnavailableException {
         s_logger.debug("Stopping router " + router);
         try {
             _itMgr.advanceStop(router.getUuid(), forced);
@@ -3535,7 +3536,8 @@ Listener, Configurable {
 
     protected boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException {
         if(!checkRouterVersion(router)){
-            s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId());
+            s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion()
+                    + ", minimal required version : " + MinVRVersion);
             throw new CloudRuntimeException("Unable to send command. Upgrade in progress. Please contact administrator.");
         }
         Answer[] answers = null;


[37/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Fix several AssertionErrors caused by improper transaction handling. Rewrite to new way of doing transactions.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cbbe3e0c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cbbe3e0c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cbbe3e0c

Branch: refs/heads/rbac
Commit: cbbe3e0cd7c2a5bbb73584e8dc71746fe01f5b78
Parents: 1baebeb
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Thu Feb 6 16:49:05 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Thu Feb 6 16:51:20 2014 +0100

----------------------------------------------------------------------
 .../cloud/server/ConfigurationServerImpl.java   | 413 ++++++++++---------
 1 file changed, 214 insertions(+), 199 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cbbe3e0c/server/src/com/cloud/server/ConfigurationServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java
index cbf3728..b8da4c8 100755
--- a/server/src/com/cloud/server/ConfigurationServerImpl.java
+++ b/server/src/com/cloud/server/ConfigurationServerImpl.java
@@ -43,15 +43,16 @@ import javax.crypto.SecretKey;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.config.ApiServiceConfiguration;
 import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
-import org.apache.log4j.Logger;
 
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
@@ -169,7 +170,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
     }
 
     @Override
-    @DB
     public void persistDefaultValues() throws InternalErrorException {
 
         // Create system user and admin user
@@ -285,7 +285,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
                             long startIPLong = NetUtils.ip2Long(startIp);
                             long endIPLong = NetUtils.ip2Long(endIp);
                             config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, vlan.getDataCenterId(), vlan.getId(), vlan.getNetworkId(),
-                                vlan.getPhysicalNetworkId());
+                                    vlan.getPhysicalNetworkId());
                         }
                     });
 
@@ -356,47 +356,52 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
     }
 
     private void initiateXenServerPVDriverVersion() {
-        String pvdriverversion = Config.XenPVdriverVersion.getDefaultValue();
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
-        PreparedStatement pstmt = null;
-        ResultSet rs1 = null;
-        ResultSet rs2 = null;
-        try {
-            String oldValue = _configDao.getValue(Config.XenPVdriverVersion.key());
-            if (oldValue == null) {
-                String sql = "select resource from host where hypervisor_type='XenServer' and removed is null and status not in ('Error', 'Removed') group by resource";
-                pstmt = txn.prepareAutoCloseStatement(sql);
-                rs1 = pstmt.executeQuery();
-                while (rs1.next()) {
-                    String resouce = rs1.getString(1); //resource column
-                    if (resouce == null)
-                        continue;
-                    if (resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56Resource") ||
-                        resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56FP1Resource") ||
-                        resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56SP2Resource") ||
-                        resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer600Resource") ||
-                        resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer602Resource")) {
-                        pvdriverversion = "xenserver56";
-                        break;
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                TransactionLegacy txn = TransactionLegacy.currentTxn();
+                String pvdriverversion = Config.XenPVdriverVersion.getDefaultValue();
+                PreparedStatement pstmt = null;
+                ResultSet rs1 = null;
+                ResultSet rs2 = null;
+                try {
+                    String oldValue = _configDao.getValue(Config.XenPVdriverVersion.key());
+                    if (oldValue == null) {
+                        String sql = "select resource from host where hypervisor_type='XenServer' and removed is null and status not in ('Error', 'Removed') group by resource";
+                        pstmt = txn.prepareAutoCloseStatement(sql);
+                        rs1 = pstmt.executeQuery();
+                        while (rs1.next()) {
+                            String resouce = rs1.getString(1); //resource column
+                            if (resouce == null)
+                                continue;
+                            if (resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56Resource")
+                                    || resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56FP1Resource")
+                                    || resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56SP2Resource")
+                                    || resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer600Resource")
+                                    || resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer602Resource")) {
+                                pvdriverversion = "xenserver56";
+                                break;
+                            }
+                        }
+                        _configDao.getValueAndInitIfNotExist(Config.XenPVdriverVersion.key(), Config.XenPVdriverVersion.getCategory(), pvdriverversion,
+                                Config.XenPVdriverVersion.getDescription());
+                        sql = "select id from vm_template where hypervisor_type='XenServer'  and format!='ISO' and removed is null";
+                        pstmt = txn.prepareAutoCloseStatement(sql);
+                        rs2 = pstmt.executeQuery();
+                        List<Long> tmpl_ids = new ArrayList<Long>();
+                        while (rs2.next()) {
+                            tmpl_ids.add(rs2.getLong(1));
+                        }
+                        for (Long tmpl_id : tmpl_ids) {
+                            templateDetailsInitIfNotExist(tmpl_id, "hypervisortoolsversion", pvdriverversion);
+                        }
                     }
-                }
-                _configDao.getValueAndInitIfNotExist(Config.XenPVdriverVersion.key(), Config.XenPVdriverVersion.getCategory(), pvdriverversion,
-                    Config.XenPVdriverVersion.getDescription());
-                sql = "select id from vm_template where hypervisor_type='XenServer'  and format!='ISO' and removed is null";
-                pstmt = txn.prepareAutoCloseStatement(sql);
-                rs2 = pstmt.executeQuery();
-                List<Long> tmpl_ids = new ArrayList<Long>();
-                while (rs2.next()) {
-                    tmpl_ids.add(rs2.getLong(1));
-                }
-                for (Long tmpl_id : tmpl_ids) {
-                    templateDetailsInitIfNotExist(tmpl_id, "hypervisortoolsversion", pvdriverversion);
+                } catch (Exception e) {
+                    s_logger.debug("initiateXenServerPVDriverVersion failed due to " + e.toString());
+                    // ignore
                 }
             }
-        } catch (Exception e) {
-            s_logger.debug("initiateXenServerPVDriverVersion failed due to " + e.toString());
-            // ignore
-        }
+        });
     }
 
     /*
@@ -446,92 +451,92 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
     }
 
     @DB
-    protected void saveUser() {
-        // insert system account
-        String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (1, UUID(), 'system', '1', '1', 1)";
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
-            stmt.executeUpdate();
-        } catch (SQLException ex) {
-        }
-        // insert system user
-        insertSql =
-            "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)"
-                + " VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), 1)";
-        txn = TransactionLegacy.currentTxn();
-        try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
-            stmt.executeUpdate();
-        } catch (SQLException ex) {
-        }
-
-        // insert admin user, but leave the account disabled until we set a
-        // password with the user authenticator
-        long id = 2;
-        String username = "admin";
-        String firstname = "admin";
-        String lastname = "cloud";
-
-        // create an account for the admin user first
-        insertSql =
-            "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', 1)";
-        txn = TransactionLegacy.currentTxn();
-        try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
-            stmt.executeUpdate();
-        } catch (SQLException ex) {
-        }
+    public void saveUser() {
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                TransactionLegacy txn = TransactionLegacy.currentTxn();
+                // insert system account
+                String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (1, UUID(), 'system', '1', '1', 1)";
 
-        // now insert the user
-        insertSql =
-            "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, state, user.default) " + "VALUES (" + id +
-                ", UUID(), '" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', 1)";
+                try {
+                    PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+                    stmt.executeUpdate();
+                } catch (SQLException ex) {
+                }
+                // insert system user
+                insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)"
+                        + " VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), 1)";
 
-        txn = TransactionLegacy.currentTxn();
-        try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
-            stmt.executeUpdate();
-        } catch (SQLException ex) {
-        }
+                try {
+                    PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+                    stmt.executeUpdate();
+                } catch (SQLException ex) {
+                }
 
-        try {
-            String tableName = "security_group";
-            try {
-                String checkSql = "SELECT * from network_group";
-                PreparedStatement stmt = txn.prepareAutoCloseStatement(checkSql);
-                stmt.executeQuery();
-                tableName = "network_group";
-            } catch (Exception ex) {
-                // if network_groups table exists, create the default security group there
-            }
+                // insert admin user, but leave the account disabled until we set a
+                // password with the user authenticator
+                long id = 2;
+                String username = "admin";
+                String firstname = "admin";
+                String lastname = "cloud";
 
-            insertSql = "SELECT * FROM " + tableName + " where account_id=2 and name='default'";
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
-            ResultSet rs = stmt.executeQuery();
-            if (!rs.next()) {
-                // save default security group
-                if (tableName.equals("security_group")) {
-                    insertSql =
-                        "INSERT INTO " + tableName + " (uuid, name, description, account_id, domain_id) " + "VALUES (UUID(), 'default', 'Default Security Group', 2, 1)";
-                } else {
-                    insertSql =
-                        "INSERT INTO " + tableName + " (name, description, account_id, domain_id, account_name) " +
-                            "VALUES ('default', 'Default Security Group', 2, 1, 'admin')";
+                // create an account for the admin user first
+                insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (" + id + ", UUID(), '" + username
+                        + "', '1', '1', 1)";
+                try {
+                    PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+                    stmt.executeUpdate();
+                } catch (SQLException ex) {
                 }
 
-                txn = TransactionLegacy.currentTxn();
+                // now insert the user
+                insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, state, user.default) " + "VALUES (" + id
+                        + ", UUID(), '" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', 1)";
+
                 try {
-                    stmt = txn.prepareAutoCloseStatement(insertSql);
+                    PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
                     stmt.executeUpdate();
                 } catch (SQLException ex) {
+                }
+
+                try {
+                    String tableName = "security_group";
+                    try {
+                        String checkSql = "SELECT * from network_group";
+                        PreparedStatement stmt = txn.prepareAutoCloseStatement(checkSql);
+                        stmt.executeQuery();
+                        tableName = "network_group";
+                    } catch (Exception ex) {
+                        // if network_groups table exists, create the default security group there
+                    }
+
+                    insertSql = "SELECT * FROM " + tableName + " where account_id=2 and name='default'";
+                    PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+                    ResultSet rs = stmt.executeQuery();
+                    if (!rs.next()) {
+                        // save default security group
+                        if (tableName.equals("security_group")) {
+                            insertSql = "INSERT INTO " + tableName + " (uuid, name, description, account_id, domain_id) "
+                                    + "VALUES (UUID(), 'default', 'Default Security Group', 2, 1)";
+                        } else {
+                            insertSql = "INSERT INTO " + tableName + " (name, description, account_id, domain_id, account_name) "
+                                    + "VALUES ('default', 'Default Security Group', 2, 1, 'admin')";
+                        }
+
+                        try {
+                            stmt = txn.prepareAutoCloseStatement(insertSql);
+                            stmt.executeUpdate();
+                        } catch (SQLException ex) {
+                            s_logger.warn("Failed to create default security group for default admin account due to ", ex);
+                        }
+                    }
+                    rs.close();
+                } catch (Exception ex) {
                     s_logger.warn("Failed to create default security group for default admin account due to ", ex);
                 }
             }
-            rs.close();
-        } catch (Exception ex) {
-            s_logger.warn("Failed to create default security group for default admin account due to ", ex);
-        }
+        });
     }
 
     protected void updateCloudIdentifier() {
@@ -620,8 +625,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
                 }
                 String base64Keystore = getBase64Keystore(keystorePath);
                 ConfigurationVO configVO =
-                    new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", DBEncryptionUtil.encrypt(base64Keystore),
-                        "SSL Keystore for the management servers");
+                        new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", DBEncryptionUtil.encrypt(base64Keystore),
+                                "SSL Keystore for the management servers");
                 _configDao.persist(configVO);
                 s_logger.info("Stored SSL keystore to database.");
             } else if (null != keystoreFile && keystoreFile.exists()) { // and dbExisted
@@ -677,9 +682,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
             try {
                 String rpassword = PasswordGenerator.generatePresharedKey(8);
                 String wSql =
-                    "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
-                        "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', '" + DBEncryptionUtil.encrypt(rpassword) +
-                        "','randmon password generated each management server starts for system vm')";
+                        "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
+                                "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', '" + DBEncryptionUtil.encrypt(rpassword) +
+                                "','randmon password generated each management server starts for system vm')";
                 PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql);
                 stmt.executeUpdate(wSql);
                 s_logger.info("Updated systemvm password in database");
@@ -753,37 +758,43 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
             }
             String publicKey = new String(arr2).trim();
 
-            String insertSql1 =
-                "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
-                    "VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '" + DBEncryptionUtil.encrypt(privateKey) +
-                    "','Private key for the entire CloudStack')";
-            String insertSql2 =
-                "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
-                    "VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '" + DBEncryptionUtil.encrypt(publicKey) +
-                    "','Public key for the entire CloudStack')";
+            final String insertSql1 =
+                    "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
+                            "VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '" + DBEncryptionUtil.encrypt(privateKey) +
+                            "','Private key for the entire CloudStack')";
+            final String insertSql2 =
+                    "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
+                            "VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '" + DBEncryptionUtil.encrypt(publicKey) +
+                            "','Public key for the entire CloudStack')";
 
-            TransactionLegacy txn = TransactionLegacy.currentTxn();
-            try {
-                PreparedStatement stmt1 = txn.prepareAutoCloseStatement(insertSql1);
-                stmt1.executeUpdate();
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Private key inserted into database");
-                }
-            } catch (SQLException ex) {
-                s_logger.error("SQL of the private key failed", ex);
-                throw new CloudRuntimeException("SQL of the private key failed");
-            }
+            Transaction.execute(new TransactionCallbackNoReturn() {
+                @Override
+                public void doInTransactionWithoutResult(TransactionStatus status) {
+
+                    TransactionLegacy txn = TransactionLegacy.currentTxn();
+                    try {
+                        PreparedStatement stmt1 = txn.prepareAutoCloseStatement(insertSql1);
+                        stmt1.executeUpdate();
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Private key inserted into database");
+                        }
+                    } catch (SQLException ex) {
+                        s_logger.error("SQL of the private key failed", ex);
+                        throw new CloudRuntimeException("SQL of the private key failed");
+                    }
 
-            try {
-                PreparedStatement stmt2 = txn.prepareAutoCloseStatement(insertSql2);
-                stmt2.executeUpdate();
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Public key inserted into database");
+                    try {
+                        PreparedStatement stmt2 = txn.prepareAutoCloseStatement(insertSql2);
+                        stmt2.executeUpdate();
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Public key inserted into database");
+                        }
+                    } catch (SQLException ex) {
+                        s_logger.error("SQL of the public key failed", ex);
+                        throw new CloudRuntimeException("SQL of the public key failed");
+                    }
                 }
-            } catch (SQLException ex) {
-                s_logger.error("SQL of the public key failed", ex);
-                throw new CloudRuntimeException("SQL of the public key failed");
-            }
+            });
 
         } else {
             s_logger.info("Keypairs already in database, updating local copy");
@@ -892,20 +903,24 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
             s_logger.info("Need to store secondary storage vm copy password in the database");
             String password = PasswordGenerator.generateRandomPassword(12);
 
-            String insertSql1 =
-                "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
-                    "VALUES ('Hidden','DEFAULT', 'management-server','secstorage.copy.password', '" + DBEncryptionUtil.encrypt(password) +
-                    "','Password used to authenticate zone-to-zone template copy requests')";
-
-            TransactionLegacy txn = TransactionLegacy.currentTxn();
-            try {
-                PreparedStatement stmt1 = txn.prepareAutoCloseStatement(insertSql1);
-                stmt1.executeUpdate();
-                s_logger.debug("secondary storage vm copy password inserted into database");
-            } catch (SQLException ex) {
-                s_logger.warn("Failed to insert secondary storage vm copy password", ex);
-            }
-
+            final String insertSql1 =
+                    "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
+                            "VALUES ('Hidden','DEFAULT', 'management-server','secstorage.copy.password', '" + DBEncryptionUtil.encrypt(password) +
+                            "','Password used to authenticate zone-to-zone template copy requests')";
+            Transaction.execute(new TransactionCallbackNoReturn() {
+                @Override
+                public void doInTransactionWithoutResult(TransactionStatus status) {
+
+                    TransactionLegacy txn = TransactionLegacy.currentTxn();
+                    try {
+                        PreparedStatement stmt1 = txn.prepareAutoCloseStatement(insertSql1);
+                        stmt1.executeUpdate();
+                        s_logger.debug("secondary storage vm copy password inserted into database");
+                    } catch (SQLException ex) {
+                        s_logger.warn("Failed to insert secondary storage vm copy password", ex);
+                    }
+                }
+            });
         }
     }
 
@@ -926,7 +941,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
 
     @DB
     protected HostPodVO createPod(long userId, String podName, final long zoneId, String gateway, String cidr, final String startIp, String endIp)
-        throws InternalErrorException {
+            throws InternalErrorException {
         String[] cidrPair = cidr.split("\\/");
         String cidrAddress = cidrPair[0];
         int cidrSize = Integer.parseInt(cidrPair[1]);
@@ -985,7 +1000,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
     }
 
     private DiskOfferingVO createdefaultDiskOffering(Long domainId, String name, String description, int numGibibytes, String tags, boolean isCustomized,
-        boolean isSystemUse) {
+            boolean isSystemUse) {
         long diskSize = numGibibytes;
         diskSize = diskSize * 1024 * 1024 * 1024;
         tags = cleanupTags(tags);
@@ -998,10 +1013,10 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
     }
 
     private ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
-        boolean offerHA, String tags) {
+            boolean offerHA, String tags) {
         tags = cleanupTags(tags);
         ServiceOfferingVO offering =
-            new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, null, false);
+                new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, null, false);
         offering.setUniqueName("Cloud.Com-" + name);
         offering = _serviceOfferingDao.persistSystemServiceOffering(offering);
         return offering;
@@ -1076,87 +1091,87 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
             public void doInTransactionWithoutResult(TransactionStatus status) {
                 // Offering #1
                 NetworkOfferingVO defaultSharedSGNetworkOffering =
-                    new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks",
-                        TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks",
+                                TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false);
 
                 defaultSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled);
                 defaultSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedSGNetworkOffering);
 
                 for (Service service : defaultSharedSGNetworkOfferingProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultSharedSGNetworkOffering.getId(), service, defaultSharedSGNetworkOfferingProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultSharedSGNetworkOffering.getId(), service, defaultSharedSGNetworkOfferingProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #2
                 NetworkOfferingVO defaultSharedNetworkOffering =
-                    new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, false, true, null, null, true,
-                        Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, false, true, null, null, true,
+                                Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false);
 
                 defaultSharedNetworkOffering.setState(NetworkOffering.State.Enabled);
                 defaultSharedNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedNetworkOffering);
 
                 for (Service service : defaultSharedNetworkOfferingProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultSharedNetworkOffering.getId(), service, defaultSharedNetworkOfferingProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultSharedNetworkOffering.getId(), service, defaultSharedNetworkOfferingProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #3
                 NetworkOfferingVO defaultIsolatedSourceNatEnabledNetworkOffering =
-                    new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
-                        "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, null,
-                        Network.GuestType.Isolated, true, false, false, false, true);
+                        new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
+                                "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, null,
+                                Network.GuestType.Isolated, true, false, false, false, true);
 
                 defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
                 defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering);
 
                 for (Service service : defaultIsolatedSourceNatEnabledNetworkOfferingProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service,
-                            defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service,
+                                    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #4
                 NetworkOfferingVO defaultIsolatedEnabledNetworkOffering =
-                    new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest,
-                        false, true, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, true, true, false, false, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest,
+                                false, true, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, true, true, false, false, false);
 
                 defaultIsolatedEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
                 defaultIsolatedEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedEnabledNetworkOffering);
 
                 for (Service service : defaultIsolatedNetworkOfferingProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultIsolatedEnabledNetworkOffering.getId(), service, defaultIsolatedNetworkOfferingProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultIsolatedEnabledNetworkOffering.getId(), service, defaultIsolatedNetworkOfferingProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #5
                 NetworkOfferingVO defaultNetscalerNetworkOffering =
-                    new NetworkOfferingVO(NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
-                        "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true,
-                        Availability.Optional, null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
+                                "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true,
+                                Availability.Optional, null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false, false);
 
                 defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled);
                 defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering);
 
                 for (Service service : netscalerServiceProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultNetscalerNetworkOffering.getId(), service, netscalerServiceProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultNetscalerNetworkOffering.getId(), service, netscalerServiceProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #6
                 NetworkOfferingVO defaultNetworkOfferingForVpcNetworks =
-                    new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
-                        "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional,
-                        null, Network.GuestType.Isolated, false, false, false, false, true);
+                        new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
+                                "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional,
+                                null, Network.GuestType.Isolated, false, false, false, false, true);
 
                 defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled);
                 defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks);
@@ -1175,16 +1190,16 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
 
                 for (Service service : defaultVpcNetworkOfferingProviders.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service));
+                            new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 // Offering #7
                 NetworkOfferingVO defaultNetworkOfferingForVpcNetworksNoLB =
-                    new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
-                        "Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled", TrafficType.Guest, false, false, null, null, true,
-                        Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
+                                "Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled", TrafficType.Guest, false, false, null, null, true,
+                                Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
 
                 defaultNetworkOfferingForVpcNetworksNoLB.setState(NetworkOffering.State.Enabled);
                 defaultNetworkOfferingForVpcNetworksNoLB = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworksNoLB);
@@ -1202,16 +1217,16 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
 
                 for (Service service : defaultVpcNetworkOfferingProvidersNoLB.keySet()) {
                     NetworkOfferingServiceMapVO offService =
-                        new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), service, defaultVpcNetworkOfferingProvidersNoLB.get(service));
+                            new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), service, defaultVpcNetworkOfferingProvidersNoLB.get(service));
                     _ntwkOfferingServiceMapDao.persist(offService);
                     s_logger.trace("Added service for the network offering: " + offService);
                 }
 
                 //offering #8 - network offering with internal lb service
                 NetworkOfferingVO internalLbOff =
-                    new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB,
-                        "Offering for Isolated Vpc networks with Internal LB support", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null,
-                        Network.GuestType.Isolated, false, false, false, true, false);
+                        new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB,
+                                "Offering for Isolated Vpc networks with Internal LB support", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null,
+                                Network.GuestType.Isolated, false, false, false, true, false);
 
                 internalLbOff.setState(NetworkOffering.State.Enabled);
                 internalLbOff = _networkOfferingDao.persistDefaultNetworkOffering(internalLbOff);
@@ -1286,8 +1301,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
 
                     if (broadcastDomainType != null) {
                         NetworkVO network =
-                            new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain,
-                                Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null);
+                                new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain,
+                                        Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null);
                         network.setGuruName(guruNames.get(network.getTrafficType()));
                         network.setDns1(zone.getDns1());
                         network.setDns2(zone.getDns2());


[14/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-5932: updated script with the valid iso download urls


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/18191ce7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/18191ce7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/18191ce7

Branch: refs/heads/rbac
Commit: 18191ce79aa7c37c0cf4f0dc072809a44e878709
Parents: 0d222b1
Author: Abhinandan Prateek <ap...@apache.org>
Authored: Thu Jan 23 15:24:06 2014 +0530
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 10:38:26 2014 +0100

----------------------------------------------------------------------
 tools/appliance/definitions/systemvm64template/definition.rb | 4 ++--
 tools/appliance/definitions/systemvmtemplate/definition.rb   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18191ce7/tools/appliance/definitions/systemvm64template/definition.rb
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvm64template/definition.rb b/tools/appliance/definitions/systemvm64template/definition.rb
index 454145d..ba2659c 100644
--- a/tools/appliance/definitions/systemvm64template/definition.rb
+++ b/tools/appliance/definitions/systemvm64template/definition.rb
@@ -4,8 +4,8 @@ Veewee::Definition.declare({
   :disk_size => '2500', :disk_format => 'VDI', :hostiocache => 'off',
   :os_type_id => 'Debian_64',
   :iso_file => "debian-7.0.0-amd64-netinst.iso",
-  :iso_src => "http://cdimage.debian.org/mirror/cdimage/archive/7.0.0/amd64/iso-cd/debian-7.0.0-amd64-netinst.iso",
-  :iso_md5 => "6a55096340b5b1b7d335d5b559e13ea0",
+  :iso_src => "http://ftp.acc.umu.se/mirror/cdimage/release/7.3.0/amd64/iso-cd/debian-7.3.0-amd64-netinst.iso",
+  :iso_md5 => "72473e8a5e65b61acc7efde90d9f71d1",
   :iso_download_timeout => "1000",
   :boot_wait => "10", :boot_cmd_sequence => [
      '<Esc>',

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18191ce7/tools/appliance/definitions/systemvmtemplate/definition.rb
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/definition.rb b/tools/appliance/definitions/systemvmtemplate/definition.rb
index 33f25b2..1717552 100644
--- a/tools/appliance/definitions/systemvmtemplate/definition.rb
+++ b/tools/appliance/definitions/systemvmtemplate/definition.rb
@@ -4,8 +4,8 @@ Veewee::Definition.declare({
   :disk_size => '2500', :disk_format => 'VDI', :hostiocache => 'off',
   :os_type_id => 'Debian',
   :iso_file => "debian-7.0.0-i386-netinst.iso",
-  :iso_src => "http://cdimage.debian.org/mirror/cdimage/archive/7.0.0/i386/iso-cd/debian-7.0.0-i386-netinst.iso",
-  :iso_md5 => "a6b93666a5393334accb7ac4ee28d949",
+  :iso_src => "http://ftp.acc.umu.se/mirror/cdimage/release/7.3.0/i386/iso-cd/debian-7.3.0-i386-netinst.iso",
+  :iso_md5 => "04c58f30744e64a0459caf7d7cace479",
   :iso_download_timeout => "1000",
   :boot_wait => "10", :boot_cmd_sequence => [
      '<Esc>',


[49/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Instances UI: Fix case where 'list host' is visible for stopped VM


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/33846338
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/33846338
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/33846338

Branch: refs/heads/rbac
Commit: 3384633834a75c5bd2922e08ea7328aece63085d
Parents: b6db18f
Author: Brian Federle <br...@citrix.com>
Authored: Fri Feb 7 11:08:43 2014 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Fri Feb 7 11:09:18 2014 -0800

----------------------------------------------------------------------
 ui/scripts/instances.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/33846338/ui/scripts/instances.js
----------------------------------------------------------------------
diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js
index 3b1931b..cd18f83 100644
--- a/ui/scripts/instances.js
+++ b/ui/scripts/instances.js
@@ -504,7 +504,7 @@
                                         _custom: {
                                             jobId: jid,
                                             getUpdatedItem: function(json) {
-                                                return json.queryasyncjobresultresponse.jobresult.virtualmachine;
+                                                return $.extend(json.queryasyncjobresultresponse.jobresult.virtualmachine, { hostid: null });
                                             },
                                             getActionFilter: function() {
                                                 return vmActionfilter;


[40/50] [abbrv] Revert "CLOUDSTACK-6003 fixing plus refactoring dispatcher" as it breaks API dispatching for commands having Map as a parameter type

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index 23ae50c..3159059 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@ -83,8 +83,6 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
     protected VolumeDao _volsDao;
     @Inject
     protected ConfigurationDao _configDao;
-    @Inject
-    protected ApiDispatcher _dispatcher;
 
     protected AsyncJobDispatcher _asyncDispatcher;
 
@@ -98,21 +96,21 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
         return _asyncDispatcher;
     }
 
-    public void setAsyncJobDispatcher(final AsyncJobDispatcher dispatcher) {
+    public void setAsyncJobDispatcher(AsyncJobDispatcher dispatcher) {
         _asyncDispatcher = dispatcher;
     }
 
-    private Date getNextScheduledTime(final long policyId, final Date currentTimestamp) {
-        final SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
+    private Date getNextScheduledTime(long policyId, Date currentTimestamp) {
+        SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
         Date nextTimestamp = null;
         if (policy != null) {
-            final short intervalType = policy.getInterval();
-            final IntervalType type = DateUtil.getIntervalType(intervalType);
-            final String schedule = policy.getSchedule();
-            final String timezone = policy.getTimezone();
+            short intervalType = policy.getInterval();
+            IntervalType type = DateUtil.getIntervalType(intervalType);
+            String schedule = policy.getSchedule();
+            String timezone = policy.getTimezone();
             nextTimestamp = DateUtil.getNextRunTime(type, schedule, timezone, currentTimestamp);
-            final String currentTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, currentTimestamp);
-            final String nextScheduledTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, nextTimestamp);
+            String currentTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, currentTimestamp);
+            String nextScheduledTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, nextTimestamp);
             s_logger.debug("Current time is " + currentTime + ". NextScheduledTime of policyId " + policyId + " is " + nextScheduledTime);
         }
         return nextTimestamp;
@@ -122,7 +120,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
      * {@inheritDoc}
      */
     @Override
-    public void poll(final Date currentTimestamp) {
+    public void poll(Date currentTimestamp) {
         // We don't maintain the time. The timer task does.
         _currentTimestamp = currentTimestamp;
 
@@ -154,12 +152,12 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
     }
 
     private void checkStatusOfCurrentlyExecutingSnapshots() {
-        final SearchCriteria<SnapshotScheduleVO> sc = _snapshotScheduleDao.createSearchCriteria();
+        SearchCriteria<SnapshotScheduleVO> sc = _snapshotScheduleDao.createSearchCriteria();
         sc.addAnd("asyncJobId", SearchCriteria.Op.NNULL);
-        final List<SnapshotScheduleVO> snapshotSchedules = _snapshotScheduleDao.search(sc, null);
-        for (final SnapshotScheduleVO snapshotSchedule : snapshotSchedules) {
-            final Long asyncJobId = snapshotSchedule.getAsyncJobId();
-            final AsyncJobVO asyncJob = _asyncJobDao.findById(asyncJobId);
+        List<SnapshotScheduleVO> snapshotSchedules = _snapshotScheduleDao.search(sc, null);
+        for (SnapshotScheduleVO snapshotSchedule : snapshotSchedules) {
+            Long asyncJobId = snapshotSchedule.getAsyncJobId();
+            AsyncJobVO asyncJob = _asyncJobDao.findById(asyncJobId);
             switch (asyncJob.getStatus()) {
                 case SUCCEEDED:
                     // The snapshot has been successfully backed up.
@@ -170,7 +168,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
                     break;
                 case FAILED:
                     // Check the snapshot status.
-                    final Long snapshotId = snapshotSchedule.getSnapshotId();
+                    Long snapshotId = snapshotSchedule.getSnapshotId();
                     if (snapshotId == null) {
                         // createSnapshotAsync exited, successfully or unsuccessfully,
                         // even before creating a snapshot record
@@ -178,7 +176,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
                         // Schedule the next snapshot.
                         scheduleNextSnapshotJob(snapshotSchedule);
                     } else {
-                        final SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
+                        SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
                         if (snapshot == null || snapshot.getRemoved() != null) {
                             // This snapshot has been deleted successfully from the primary storage
                             // Again no cleanup needs to be done.
@@ -222,16 +220,16 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
         String displayTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, _currentTimestamp);
         s_logger.debug("Snapshot scheduler.poll is being called at " + displayTime);
 
-        final List<SnapshotScheduleVO> snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp);
+        List<SnapshotScheduleVO> snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp);
         s_logger.debug("Got " + snapshotsToBeExecuted.size() + " snapshots to be executed at " + displayTime);
 
-        for (final SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) {
+        for (SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) {
             SnapshotScheduleVO tmpSnapshotScheduleVO = null;
-            final long snapshotScheId = snapshotToBeExecuted.getId();
-            final long policyId = snapshotToBeExecuted.getPolicyId();
-            final long volumeId = snapshotToBeExecuted.getVolumeId();
+            long snapshotScheId = snapshotToBeExecuted.getId();
+            long policyId = snapshotToBeExecuted.getPolicyId();
+            long volumeId = snapshotToBeExecuted.getVolumeId();
             try {
-                final VolumeVO volume = _volsDao.findById(volumeId);
+                VolumeVO volume = _volsDao.findById(volumeId);
                 if (volume.getPoolId() == null) {
                     // this volume is not attached
                     continue;
@@ -240,41 +238,40 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
                     _snapshotScheduleDao.remove(snapshotToBeExecuted.getId());
                 }
                 if (s_logger.isDebugEnabled()) {
-                    final Date scheduledTimestamp = snapshotToBeExecuted.getScheduledTimestamp();
+                    Date scheduledTimestamp = snapshotToBeExecuted.getScheduledTimestamp();
                     displayTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, scheduledTimestamp);
                     s_logger.debug("Scheduling 1 snapshot for volume " + volumeId + " for schedule id: " + snapshotToBeExecuted.getId() + " at " + displayTime);
                 }
 
                 tmpSnapshotScheduleVO = _snapshotScheduleDao.acquireInLockTable(snapshotScheId);
-                final Long eventId =
+                Long eventId =
                     ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_SNAPSHOT_CREATE, "creating snapshot for volume Id:" +
                         volumeId, 0);
 
-                final Map<String, Object> params = new HashMap<String, Object>();
+                Map<String, String> params = new HashMap<String, String>();
                 params.put(ApiConstants.VOLUME_ID, "" + volumeId);
                 params.put(ApiConstants.POLICY_ID, "" + policyId);
                 params.put("ctxUserId", "1");
                 params.put("ctxAccountId", "" + volume.getAccountId());
                 params.put("ctxStartEventId", String.valueOf(eventId));
 
-                final CreateSnapshotCmd cmd = new CreateSnapshotCmd();
+                CreateSnapshotCmd cmd = new CreateSnapshotCmd();
                 ComponentContext.inject(cmd);
-                _dispatcher.dispatchCreateCmd(cmd, params);
+                ApiDispatcher.getInstance().dispatchCreateCmd(cmd, params);
                 params.put("id", "" + cmd.getEntityId());
                 params.put("ctxStartEventId", "1");
 
-                final AsyncJobVO job =
+                AsyncJobVO job =
                     new AsyncJobVO(UUID.randomUUID().toString(), User.UID_SYSTEM, volume.getAccountId(), CreateSnapshotCmd.class.getName(), ApiGsonHelper.getBuilder()
                         .create()
                         .toJson(params), cmd.getEntityId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null);
                 job.setDispatcher(_asyncDispatcher.getName());
 
-                final long jobId = _asyncMgr.submitAsyncJob(job);
+                long jobId = _asyncMgr.submitAsyncJob(job);
 
                 tmpSnapshotScheduleVO.setAsyncJobId(jobId);
                 _snapshotScheduleDao.update(snapshotScheId, tmpSnapshotScheduleVO);
-            } catch (final Exception e) {
-                // TODO Logging this exception is enough?
+            } catch (Exception e) {
                 s_logger.warn("Scheduling snapshot failed due to " + e.toString());
             } finally {
                 if (tmpSnapshotScheduleVO != null) {
@@ -284,16 +281,16 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
         }
     }
 
-    private Date scheduleNextSnapshotJob(final SnapshotScheduleVO snapshotSchedule) {
+    private Date scheduleNextSnapshotJob(SnapshotScheduleVO snapshotSchedule) {
         if (snapshotSchedule == null) {
             return null;
         }
-        final Long policyId = snapshotSchedule.getPolicyId();
+        Long policyId = snapshotSchedule.getPolicyId();
         if (policyId.longValue() == Snapshot.MANUAL_POLICY_ID) {
             // Don't need to schedule the next job for this.
             return null;
         }
-        final SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
+        SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
         if (snapshotPolicy == null) {
             _snapshotScheduleDao.expunge(snapshotSchedule.getId());
         }
@@ -302,15 +299,15 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
 
     @Override
     @DB
-    public Date scheduleNextSnapshotJob(final SnapshotPolicyVO policy) {
+    public Date scheduleNextSnapshotJob(SnapshotPolicyVO policy) {
         if (policy == null) {
             return null;
         }
-        final long policyId = policy.getId();
+        long policyId = policy.getId();
         if (policyId == Snapshot.MANUAL_POLICY_ID) {
             return null;
         }
-        final Date nextSnapshotTimestamp = getNextScheduledTime(policyId, _currentTimestamp);
+        Date nextSnapshotTimestamp = getNextScheduledTime(policyId, _currentTimestamp);
         SnapshotScheduleVO spstSchedVO = _snapshotScheduleDao.findOneByVolumePolicy(policy.getVolumeId(), policy.getId());
         if (spstSchedVO == null) {
             spstSchedVO = new SnapshotScheduleVO(policy.getVolumeId(), policyId, nextSnapshotTimestamp);
@@ -334,9 +331,9 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
 
     @Override
     @DB
-    public boolean removeSchedule(final Long volumeId, final Long policyId) {
+    public boolean removeSchedule(Long volumeId, Long policyId) {
         // We can only remove schedules which are in the future. Not which are already executed in the past.
-        final SnapshotScheduleVO schedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false);
+        SnapshotScheduleVO schedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false);
         boolean success = true;
         if (schedule != null) {
             success = _snapshotScheduleDao.remove(schedule.getId());
@@ -348,18 +345,18 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
     }
 
     @Override
-    public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
 
         _snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
-        final boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
+        boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
         if (snapshotsRecurringTest) {
             // look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code)
-            final int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
-            final int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
-            final int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
-            final int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
-            final int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
-            final int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
+            int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
+            int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
+            int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
+            int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
+            int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
+            int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
 
             _testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear);
         }
@@ -374,8 +371,8 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
     @DB
     public boolean start() {
         // reschedule all policies after management restart
-        final List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
-        for (final SnapshotPolicyVO policyInstance : policyInstances) {
+        List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
+        for (SnapshotPolicyVO policyInstance : policyInstances) {
             if (policyInstance.getId() != Snapshot.MANUAL_POLICY_ID) {
                 scheduleNextSnapshotJob(policyInstance);
             }
@@ -386,13 +383,13 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
             // Else it becomes too confusing.
             _testClockTimer.schedule(_testTimerTask, 100 * 1000L, 60 * 1000L);
         } else {
-            final TimerTask timerTask = new ManagedContextTimerTask() {
+            TimerTask timerTask = new ManagedContextTimerTask() {
                 @Override
                 protected void runInContext() {
                     try {
-                        final Date currentTimestamp = new Date();
+                        Date currentTimestamp = new Date();
                         poll(currentTimestamp);
-                    } catch (final Throwable t) {
+                    } catch (Throwable t) {
                         s_logger.warn("Catch throwable in snapshot scheduler ", t);
                     }
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/ApiDispatcherTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/ApiDispatcherTest.java b/server/test/com/cloud/api/ApiDispatcherTest.java
new file mode 100644
index 0000000..7314a57
--- /dev/null
+++ b/server/test/com/cloud/api/ApiDispatcherTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.context.CallContext;
+
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.User;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApiDispatcherTest {
+
+    @Mock
+    AccountManager accountManager;
+
+    public static class TestCmd extends BaseCmd {
+
+        @Parameter(name = "strparam1")
+        String strparam1;
+
+        @Parameter(name = "intparam1", type = CommandType.INTEGER)
+        int intparam1;
+
+        @Parameter(name = "boolparam1", type = CommandType.BOOLEAN)
+        boolean boolparam1;
+
+        @Override
+        public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
+            ResourceAllocationException, NetworkRuleConflictException {
+            // well documented nothing
+        }
+
+        @Override
+        public String getCommandName() {
+            return "test";
+        }
+
+        @Override
+        public long getEntityOwnerId() {
+            return 0;
+        }
+
+    }
+
+    @Before
+    public void setup() {
+        CallContext.register(Mockito.mock(User.class), Mockito.mock(Account.class));
+        new ApiDispatcher().init();
+        ApiDispatcher.getInstance()._accountMgr = accountManager;
+    }
+
+    @After
+    public void cleanup() {
+        CallContext.unregister();
+    }
+
+    @Test
+    public void processParameters() {
+        HashMap<String, String> params = new HashMap<String, String>();
+        params.put("strparam1", "foo");
+        params.put("intparam1", "100");
+        params.put("boolparam1", "true");
+        TestCmd cmd = new TestCmd();
+        //how lucky that field is not protected, this test would be impossible
+        ApiDispatcher.processParameters(cmd, params);
+        Assert.assertEquals("foo", cmd.strparam1);
+        Assert.assertEquals(100, cmd.intparam1);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/dispatch/CommandCreationWorkerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/dispatch/CommandCreationWorkerTest.java b/server/test/com/cloud/api/dispatch/CommandCreationWorkerTest.java
deleted file mode 100644
index 775fd6a..0000000
--- a/server/test/com/cloud/api/dispatch/CommandCreationWorkerTest.java
+++ /dev/null
@@ -1,48 +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.dispatch;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-
-import com.cloud.exception.ResourceAllocationException;
-
-public class CommandCreationWorkerTest {
-
-    @Test
-    public void testHandle() throws ResourceAllocationException {
-        // Prepare
-        final BaseAsyncCreateCmd asyncCreateCmd = mock(BaseAsyncCreateCmd.class);
-        final Map<String, Object> params = new HashMap<String, Object>();
-
-        // Execute
-        final CommandCreationWorker creationWorker = new CommandCreationWorker();
-
-        creationWorker.handle(asyncCreateCmd, params);
-
-        // Assert
-        verify(asyncCreateCmd, times(1)).create();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/dispatch/DispatchChainFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/dispatch/DispatchChainFactoryTest.java b/server/test/com/cloud/api/dispatch/DispatchChainFactoryTest.java
deleted file mode 100644
index 0d743d4..0000000
--- a/server/test/com/cloud/api/dispatch/DispatchChainFactoryTest.java
+++ /dev/null
@@ -1,54 +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.dispatch;
-
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
-public class DispatchChainFactoryTest {
-
-    protected static final String STANDARD_CHAIN_ERROR = "Expecting worker of class %s at index %s of StandardChain";
-    protected static final String ASYNC_CHAIN_ERROR = "Expecting worker of class %s at index %s of StandardChain";
-
-    @Test
-    public void testAllChainCreation() {
-        // Prepare
-        final DispatchChainFactory dispatchChainFactory = new DispatchChainFactory();
-        dispatchChainFactory.paramGenericValidationWorker = new ParamGenericValidationWorker();
-        dispatchChainFactory.paramSemanticValidationWorker = new ParamSemanticValidationWorker();
-        dispatchChainFactory.paramProcessWorker = new ParamProcessWorker();
-        dispatchChainFactory.commandCreationWorker = new CommandCreationWorker();
-
-        final Class<?>[] standardClasses = {ParamGenericValidationWorker.class, ParamProcessWorker.class,
-                ParamSemanticValidationWorker.class};
-        final Class<?>[] asyncClasses = {ParamGenericValidationWorker.class, ParamProcessWorker.class,
-                ParamSemanticValidationWorker.class, CommandCreationWorker.class};
-
-        // Execute
-        dispatchChainFactory.setup();
-        final DispatchChain standardChain = dispatchChainFactory.getStandardDispatchChain();
-        final DispatchChain asyncChain = dispatchChainFactory.getAsyncCreationDispatchChain();
-        for (int i = 0; i < standardClasses.length; i++) {
-            assertEquals(String.format(STANDARD_CHAIN_ERROR, standardClasses[i], i),
-                    standardClasses[i], standardChain.workers.get(i).getClass());
-        }
-        for (int i = 0; i < asyncClasses.length; i++) {
-            assertEquals(String.format(ASYNC_CHAIN_ERROR, asyncClasses[i], i),
-                    asyncClasses[i], asyncChain.workers.get(i).getClass());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java b/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java
deleted file mode 100644
index 3fd37cc..0000000
--- a/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java
+++ /dev/null
@@ -1,163 +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.dispatch;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.cloudstack.acl.RoleType;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.user.Account;
-
-import org.apache.log4j.Logger;
-
-public class ParamGenericValidationWorkerTest {
-
-    protected String loggerOutput = null;
-
-    protected void driveTest(final BaseCmd cmd, final Map<String, Object> params) {
-        final ParamGenericValidationWorker genValidationWorker = new ParamGenericValidationWorker();
-
-        // We create a mock logger to verify the result
-        ParamGenericValidationWorker.s_logger = new Logger(""){
-            @Override
-            public void warn(final Object msg){
-                loggerOutput = msg.toString();
-            }
-        };
-
-        // Execute
-        genValidationWorker.handle(cmd, params);
-    }
-
-    @Test
-    public void testHandle() throws ResourceAllocationException {
-        // Prepare
-        final BaseCmd cmd = new FakeCmd();
-        final Map<String, Object> params = new HashMap<String, Object>();
-        params.put(ApiConstants.COMMAND, "");
-        params.put("addedParam", "");
-
-        // Execute
-        driveTest(cmd, params);
-
-        // Assert
-        assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput);
-    }
-
-    @Test
-    public void testHandleWithUnknownParams() throws ResourceAllocationException {
-        // Prepare
-        final String unknownParamKey = "unknownParam";
-        final BaseCmd cmd = new FakeCmd();
-        final Map<String, Object> params = new HashMap<String, Object>();
-        params.put(ApiConstants.COMMAND, "");
-        params.put("addedParam", "");
-        params.put(unknownParamKey, "");
-
-        // Execute
-        driveTest(cmd, params);
-
-        // Assert
-        assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey));
-    }
-
-    @Test
-    public void testHandleWithoutAuthorization() throws ResourceAllocationException {
-        final short type = 2;
-        driveAuthTest(type);
-
-        // Assert
-        assertTrue("There should be error msg, since there is one unauthorized parameter", loggerOutput.contains("paramWithRole"));
-    }
-
-    @Test
-    public void testHandleWithAuthorization() throws ResourceAllocationException {
-        final short type = 1;
-        driveAuthTest(type);
-
-        // Assert
-        assertEquals("There should be no errors since parameters have authorization", null, loggerOutput);
-    }
-
-    protected void driveAuthTest(final short type) {
-        // Prepare
-        final BaseCmd cmd = new FakeCmdWithRoleAdmin();
-        final Account account = mock(Account.class);
-        ((FakeCmdWithRoleAdmin)cmd).account = account;
-        when(account.getType()).thenReturn(type);
-        final Map<String, Object> params = new HashMap<String, Object>();
-        params.put(ApiConstants.COMMAND, "");
-        params.put("addedParam", "");
-        params.put("paramWithRole", "");
-
-        // Execute
-        driveTest(cmd, params);
-    }
-}
-
-class FakeCmd extends BaseCmd {
-
-    @Parameter(name = "addedParam")
-    private String addedParam;
-
-    public Account account;
-
-    @Override
-    protected Account getCurrentContextAccount() {
-        return account;
-    }
-
-    //
-    // Dummy methods for mere correct compilation
-    //
-    @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
-            NetworkRuleConflictException {
-    }
-    @Override
-    public String getCommandName() {
-        return null;
-    }
-    @Override
-    public long getEntityOwnerId() {
-        return 0;
-    }
-}
-
-class FakeCmdWithRoleAdmin extends FakeCmd {
-
-    @Parameter(name = "paramWithRole", authorized = {RoleType.Admin})
-    private String paramWithRole;
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/dispatch/ParamProcessWorkerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/dispatch/ParamProcessWorkerTest.java b/server/test/com/cloud/api/dispatch/ParamProcessWorkerTest.java
deleted file mode 100644
index 1259713..0000000
--- a/server/test/com/cloud/api/dispatch/ParamProcessWorkerTest.java
+++ /dev/null
@@ -1,107 +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.dispatch;
-
-import java.util.HashMap;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.user.User;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ParamProcessWorkerTest {
-
-    @Mock
-    protected AccountManager accountManager;
-
-    protected ParamProcessWorker paramProcessWorker;
-
-    public static class TestCmd extends BaseCmd {
-
-        @Parameter(name = "strparam1")
-        String strparam1;
-
-        @Parameter(name = "intparam1", type = CommandType.INTEGER)
-        int intparam1;
-
-        @Parameter(name = "boolparam1", type = CommandType.BOOLEAN)
-        boolean boolparam1;
-
-        @Override
-        public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
-            ResourceAllocationException, NetworkRuleConflictException {
-            // well documented nothing
-        }
-
-        @Override
-        public String getCommandName() {
-            return "test";
-        }
-
-        @Override
-        public long getEntityOwnerId() {
-            return 0;
-        }
-
-    }
-
-    @Before
-    public void setup() {
-        CallContext.register(Mockito.mock(User.class), Mockito.mock(Account.class));
-        paramProcessWorker = new ParamProcessWorker();
-        paramProcessWorker._accountMgr = accountManager;
-    }
-
-    @After
-    public void cleanup() {
-        CallContext.unregister();
-    }
-
-    @Test
-    public void processParameters() {
-        final HashMap<String, Object> params = new HashMap<String, Object>();
-        params.put("strparam1", "foo");
-        params.put("intparam1", "100");
-        params.put("boolparam1", "true");
-        final TestCmd cmd = new TestCmd();
-        paramProcessWorker.processParameters(cmd, params);
-        Assert.assertEquals("foo", cmd.strparam1);
-        Assert.assertEquals(100, cmd.intparam1);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/test/com/cloud/api/dispatch/ParamSemanticValidationWorkerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/dispatch/ParamSemanticValidationWorkerTest.java b/server/test/com/cloud/api/dispatch/ParamSemanticValidationWorkerTest.java
deleted file mode 100644
index 920654e..0000000
--- a/server/test/com/cloud/api/dispatch/ParamSemanticValidationWorkerTest.java
+++ /dev/null
@@ -1,48 +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.dispatch;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import org.apache.cloudstack.api.BaseCmd;
-
-import com.cloud.exception.ResourceAllocationException;
-
-public class ParamSemanticValidationWorkerTest {
-
-    @Test
-    public void testHandle() throws ResourceAllocationException {
-        // Prepare
-        final BaseCmd cmd = mock(BaseCmd.class);
-        final Map<String, Object> params = new HashMap<String, Object>();
-
-        // Execute
-        final ParamSemanticValidationWorker semanticValWorker = new ParamSemanticValidationWorker();
-
-        semanticValWorker.handle(cmd, params);
-
-        // Assert
-        verify(cmd, times(1)).validateSpecificParameters(params);
-    }
-}


[12/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Moved the controlling logic for secondary storage vm into place


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/54f32a8e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/54f32a8e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/54f32a8e

Branch: refs/heads/rbac
Commit: 54f32a8e46247e2f354a70f52fef4835159887fd
Parents: 03a424e
Author: Alex Huang <al...@citrix.com>
Authored: Wed Feb 5 01:38:04 2014 +0000
Committer: Alex Huang <al...@citrix.com>
Committed: Wed Feb 5 01:39:17 2014 +0000

----------------------------------------------------------------------
 client/pom.xml                                  |    5 +
 .../spring-server-core-managers-context.xml     |    6 -
 .../PremiumSecondaryStorageManagerImpl.java     |  185 ---
 .../secondary/SecondaryStorageManagerImpl.java  | 1386 -----------------
 .../ConsoleProxyThumbnailHandler.java           |    1 +
 ...econdary-storage-controller-core-context.xml |   33 +
 .../PremiumSecondaryStorageManagerImpl.java     |  186 +++
 .../SecondaryStorageManagerImpl.java            | 1388 ++++++++++++++++++
 8 files changed, 1613 insertions(+), 1577 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 5215e0c..06a6db0 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -268,6 +268,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-controller-secondary-storage</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-engine-storage-image</artifactId>
       <version>${project.version}</version>
     </dependency>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
----------------------------------------------------------------------
diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
index 53a294e..cf04cc3 100644
--- a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
+++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
@@ -86,12 +86,6 @@
 
     <bean id="securityGroupManagerImpl2" class="com.cloud.network.security.SecurityGroupManagerImpl2" />
 
-    <bean id="premiumSecondaryStorageManagerImpl"
-        class="com.cloud.secstorage.PremiumSecondaryStorageManagerImpl">
-        <property name="secondaryStorageVmAllocators"
-            value="#{secondaryStorageVmAllocatorsRegistry.registered}" />
-    </bean>
-
     <bean id="ipv6AddressManagerImpl" class="com.cloud.network.Ipv6AddressManagerImpl" />
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java b/server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java
deleted file mode 100755
index ec2af2a..0000000
--- a/server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java
+++ /dev/null
@@ -1,185 +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.secstorage;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Command;
-import com.cloud.configuration.Config;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status;
-import com.cloud.host.dao.HostDao;
-import com.cloud.resource.ResourceManager;
-import com.cloud.storage.secondary.SecondaryStorageManagerImpl;
-import com.cloud.storage.secondary.SecondaryStorageVmManager;
-import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.Pair;
-import com.cloud.utils.db.JoinBuilder.JoinType;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.vm.SecondaryStorageVm;
-import com.cloud.vm.SecondaryStorageVmVO;
-import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.dao.SecondaryStorageVmDao;
-
-@Local(value = {SecondaryStorageVmManager.class})
-public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerImpl {
-    private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageManagerImpl.class);
-
-    private int _capacityPerSSVM = SecondaryStorageVmManager.DEFAULT_SS_VM_CAPACITY;
-    private int _standbyCapacity = SecondaryStorageVmManager.DEFAULT_STANDBY_CAPACITY;
-    private int _maxExecutionTimeMs = 1800000;
-
-    @Inject
-    SecondaryStorageVmDao _secStorageVmDao;
-    @Inject
-    CommandExecLogDao _cmdExecLogDao;
-    @Inject
-    HostDao _hostDao;
-    @Inject
-    ResourceManager _resourceMgr;
-    protected SearchBuilder<CommandExecLogVO> ActiveCommandSearch;
-    protected SearchBuilder<HostVO> HostSearch;
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        _capacityPerSSVM = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageSessionMax.key()), DEFAULT_SS_VM_CAPACITY);
-        _standbyCapacity = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageCapacityStandby.key()), DEFAULT_STANDBY_CAPACITY);
-
-        int nMaxExecutionMinutes = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageCmdExecutionTimeMax.key()), 30);
-        _maxExecutionTimeMs = nMaxExecutionMinutes * 60 * 1000;
-
-        HostSearch = _hostDao.createSearchBuilder();
-        HostSearch.and("dc", HostSearch.entity().getDataCenterId(), Op.EQ);
-        HostSearch.and("status", HostSearch.entity().getStatus(), Op.EQ);
-
-        ActiveCommandSearch = _cmdExecLogDao.createSearchBuilder();
-        ActiveCommandSearch.and("created", ActiveCommandSearch.entity().getCreated(), Op.GTEQ);
-        ActiveCommandSearch.join("hostSearch", HostSearch, ActiveCommandSearch.entity().getInstanceId(), HostSearch.entity().getId(), JoinType.INNER);
-
-        HostSearch.done();
-        ActiveCommandSearch.done();
-        return true;
-    }
-
-    @Override
-    public Pair<AfterScanAction, Object> scanPool(Long pool) {
-        long dataCenterId = pool.longValue();
-        if (!isSecondaryStorageVmRequired(dataCenterId)) {
-            return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
-        }
-
-        Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _maxExecutionTimeMs);
-
-        _cmdExecLogDao.expungeExpiredRecords(cutTime);
-
-        boolean suspendAutoLoading = !reserveStandbyCapacity();
-        if (!suspendAutoLoading) {
-            // this is a hacking, has nothing to do with console proxy, it is just a flag that primary storage is being under maintenance mode
-            String restart = _configDao.getValue("consoleproxy.restart");
-            if (restart != null && restart.equalsIgnoreCase("false")) {
-                s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode");
-                suspendAutoLoading = true;
-            }
-        }
-
-        List<SecondaryStorageVmVO> alreadyRunning =
-            _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting);
-        if (alreadyRunning.size() == 0) {
-            s_logger.info("No running secondary storage vms found in datacenter id=" + dataCenterId + ", starting one");
-
-            List<SecondaryStorageVmVO> stopped =
-                _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping);
-            if (stopped.size() == 0 || !suspendAutoLoading) {
-                List<SecondaryStorageVmVO> stopping = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Stopping);
-                if (stopping.size() > 0) {
-                    s_logger.info("Found SSVMs that are currently at stopping state, wait until they are settled");
-                    return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
-                }
-
-                expandPool(pool, SecondaryStorageVm.Role.templateProcessor);
-            }
-        }
-
-        if (!suspendAutoLoading) {
-            // this is to avoid surprises that people may accidently see two SSVMs being launched, capacity expanding only happens when we have at least the primary SSVM is up
-            if (alreadyRunning.size() == 0) {
-                s_logger.info("Primary secondary storage is not even started, wait until next turn");
-                return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
-            }
-
-            alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, dataCenterId, State.Running, State.Migrating, State.Starting);
-
-            List<CommandExecLogVO> activeCmds = listActiveCommands(dataCenterId, cutTime);
-            if (alreadyRunning.size() * _capacityPerSSVM - activeCmds.size() < _standbyCapacity) {
-                s_logger.info("secondary storage command execution standby capactiy low (running VMs: " + alreadyRunning.size() + ", active cmds: " + activeCmds.size() +
-                    "), starting a new one");
-                return new Pair<AfterScanAction, Object>(AfterScanAction.expand, SecondaryStorageVm.Role.commandExecutor);
-            }
-        }
-
-        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
-    }
-
-    @Override
-    public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
-
-        // TODO, need performance optimization
-        List<Long> vms = _secStorageVmDao.listRunningSecStorageOrderByLoad(null, zoneId);
-        for (Long vmId : vms) {
-            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(vmId);
-            HostVO host;
-            host = _resourceMgr.findHostByName(secStorageVm.getHostName());
-            if (host != null && host.getStatus() == Status.Up)
-                return new Pair<HostVO, SecondaryStorageVmVO>(host, secStorageVm);
-        }
-
-        return null;
-    }
-
-    private List<CommandExecLogVO> listActiveCommands(long dcId, Date cutTime) {
-        SearchCriteria<CommandExecLogVO> sc = ActiveCommandSearch.create();
-
-        sc.setParameters("created", cutTime);
-        sc.setJoinParameters("hostSearch", "dc", dcId);
-        sc.setJoinParameters("hostSearch", "status", Status.Up);
-
-        return _cmdExecLogDao.search(sc, null);
-    }
-
-    private boolean reserveStandbyCapacity() {
-        String value = _configDao.getValue(Config.SystemVMAutoReserveCapacity.key());
-        if (value != null && value.equalsIgnoreCase("true")) {
-            return true;
-        }
-
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
deleted file mode 100755
index 484dfbd..0000000
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ /dev/null
@@ -1,1386 +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.storage.secondary;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.config.ApiServiceConfiguration;
-import org.apache.cloudstack.context.CallContext;
-import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
-import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.RebootCommand;
-import com.cloud.agent.api.SecStorageFirewallCfgCommand;
-import com.cloud.agent.api.SecStorageSetupAnswer;
-import com.cloud.agent.api.SecStorageSetupCommand;
-import com.cloud.agent.api.SecStorageVMSetupCommand;
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupSecondaryStorageCommand;
-import com.cloud.agent.api.check.CheckSshAnswer;
-import com.cloud.agent.api.check.CheckSshCommand;
-import com.cloud.agent.api.to.NfsTO;
-import com.cloud.agent.manager.Commands;
-import com.cloud.capacity.dao.CapacityDao;
-import com.cloud.cluster.ClusterManager;
-import com.cloud.configuration.Config;
-import com.cloud.configuration.ZoneConfig;
-import com.cloud.consoleproxy.ConsoleProxyManager;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.deploy.DataCenterDeployment;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status;
-import com.cloud.host.dao.HostDao;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.info.RunningHostCountInfo;
-import com.cloud.info.RunningHostInfoAgregator;
-import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
-import com.cloud.network.Network;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.dao.IPAddressDao;
-import com.cloud.network.dao.IPAddressVO;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.rules.RulesManager;
-import com.cloud.offering.NetworkOffering;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.offerings.dao.NetworkOfferingDao;
-import com.cloud.resource.ResourceManager;
-import com.cloud.resource.ResourceStateAdapter;
-import com.cloud.resource.ServerResource;
-import com.cloud.resource.UnableDeleteHostException;
-import com.cloud.service.ServiceOfferingVO;
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.UploadVO;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.dao.SnapshotDao;
-import com.cloud.storage.dao.StoragePoolHostDao;
-import com.cloud.storage.dao.UploadDao;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.template.TemplateConstants;
-import com.cloud.template.TemplateManager;
-import com.cloud.user.Account;
-import com.cloud.user.AccountService;
-import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.Pair;
-import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.db.GlobalLock;
-import com.cloud.utils.db.QueryBuilder;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.events.SubscriptionMgr;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.NetUtils;
-import com.cloud.vm.Nic;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.SecondaryStorageVm;
-import com.cloud.vm.SecondaryStorageVmVO;
-import com.cloud.vm.SystemVmLoadScanHandler;
-import com.cloud.vm.SystemVmLoadScanner;
-import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachineGuru;
-import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.VirtualMachineName;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.dao.SecondaryStorageVmDao;
-import com.cloud.vm.dao.UserVmDetailsDao;
-import com.cloud.vm.dao.VMInstanceDao;
-
-//
-// Possible secondary storage vm state transition cases
-//        Creating -> Destroyed
-//        Creating -> Stopped --> Starting -> Running
-//        HA -> Stopped -> Starting -> Running
-//        Migrating -> Running    (if previous state is Running before it enters into Migrating state
-//        Migrating -> Stopped    (if previous state is not Running before it enters into Migrating state)
-//        Running -> HA            (if agent lost connection)
-//        Stopped -> Destroyed
-//
-//        Creating state indicates of record creating and IP address allocation are ready, it is a transient
-//         state which will soon be switching towards Running if everything goes well.
-//        Stopped state indicates the readiness of being able to start (has storage and IP resources allocated)
-//        Starting state can only be entered from Stopped states
-//
-// Starting, HA, Migrating, Creating and Running state are all counted as "Open" for available capacity calculation
-// because sooner or later, it will be driven into Running state
-//
-@Local(value = {SecondaryStorageVmManager.class})
-public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager, VirtualMachineGuru, SystemVmLoadScanHandler<Long>,
-        ResourceStateAdapter {
-    private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class);
-
-    private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30
-    // seconds
-    private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC = 180; // 3
-    // minutes
-
-    private static final int STARTUP_DELAY = 60000; // 60 seconds
-
-    private int _mgmtPort = 8250;
-
-    private List<SecondaryStorageVmAllocator> _ssVmAllocators;
-
-    @Inject
-    protected SecondaryStorageVmDao _secStorageVmDao;
-    @Inject
-    private DataCenterDao _dcDao;
-    @Inject
-    private VMTemplateDao _templateDao;
-    @Inject
-    private HostDao _hostDao;
-    @Inject
-    private StoragePoolHostDao _storagePoolHostDao;
-    @Inject
-    private AgentManager _agentMgr;
-    @Inject
-    protected NetworkOrchestrationService _networkMgr;
-    @Inject
-    protected NetworkModel _networkModel;
-    @Inject
-    protected SnapshotDao _snapshotDao;
-    @Inject
-    private ClusterManager _clusterMgr;
-
-    private SecondaryStorageListener _listener;
-
-    private ServiceOfferingVO _serviceOffering;
-
-    @Inject
-    protected ConfigurationDao _configDao;
-    @Inject
-    private ServiceOfferingDao _offeringDao;
-    @Inject
-    private AccountService _accountMgr;
-    @Inject
-    private VirtualMachineManager _itMgr;
-    @Inject
-    protected VMInstanceDao _vmDao;
-    @Inject
-    protected CapacityDao _capacityDao;
-    @Inject
-    UserVmDetailsDao _vmDetailsDao;
-    @Inject
-    protected ResourceManager _resourceMgr;
-    @Inject
-    NetworkDao _networkDao;
-    @Inject
-    NetworkOfferingDao _networkOfferingDao;
-    @Inject
-    protected IPAddressDao _ipAddressDao = null;
-    @Inject
-    protected RulesManager _rulesMgr;
-    @Inject
-    TemplateManager templateMgr;
-    @Inject
-    UploadDao _uploadDao;
-
-    @Inject
-    KeystoreManager _keystoreMgr;
-    @Inject
-    DataStoreManager _dataStoreMgr;
-    @Inject
-    ImageStoreDao _imageStoreDao;
-    @Inject
-    TemplateDataStoreDao _tmplStoreDao;
-    private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
-    private int _secStorageVmMtuSize;
-
-    private String _instance;
-    private boolean _useLocalStorage;
-    private boolean _useSSlCopy;
-    private String _httpProxy;
-    private String _allowedInternalSites;
-    protected long _nodeId = ManagementServerNode.getManagementServerId();
-
-    private SystemVmLoadScanner<Long> _loadScanner;
-    private Map<Long, ZoneHostInfo> _zoneHostInfoMap; // map <zone id, info about running host in zone>
-
-    private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName());
-
-    public SecondaryStorageManagerImpl() {
-    }
-
-    @Override
-    public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) {
-        try {
-            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
-            _itMgr.advanceStart(secStorageVm.getUuid(), null, null);
-            return _secStorageVmDao.findById(secStorageVm.getId());
-        } catch (StorageUnavailableException e) {
-            s_logger.warn("Exception while trying to start secondary storage vm", e);
-            return null;
-        } catch (InsufficientCapacityException e) {
-            s_logger.warn("Exception while trying to start secondary storage vm", e);
-            return null;
-        } catch (ResourceUnavailableException e) {
-            s_logger.warn("Exception while trying to start secondary storage vm", e);
-            return null;
-        } catch (Exception e) {
-            s_logger.warn("Exception while trying to start secondary storage vm", e);
-            return null;
-        }
-    }
-
-    SecondaryStorageVmVO getSSVMfromHost(HostVO ssAHost) {
-        if (ssAHost.getType() == Host.Type.SecondaryStorageVM) {
-            return _secStorageVmDao.findByInstanceName(ssAHost.getName());
-        }
-        return null;
-    }
-
-    @Override
-    public boolean generateSetupCommand(Long ssHostId) {
-        HostVO cssHost = _hostDao.findById(ssHostId);
-        Long zoneId = cssHost.getDataCenterId();
-        if (cssHost.getType() == Host.Type.SecondaryStorageVM) {
-
-            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(cssHost.getName());
-            if (secStorageVm == null) {
-                s_logger.warn("secondary storage VM " + cssHost.getName() + " doesn't exist");
-                return false;
-            }
-
-            List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
-            for (DataStore ssStore : ssStores) {
-                if (!(ssStore.getTO() instanceof NfsTO)) {
-                    continue; // only do this for Nfs
-                }
-                String secUrl = ssStore.getUri();
-                SecStorageSetupCommand setupCmd = null;
-                if (!_useSSlCopy) {
-                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
-                } else {
-                    KeystoreManager.Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
-                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
-                }
-
-                Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
-                if (answer != null && answer.getResult()) {
-                    SecStorageSetupAnswer an = (SecStorageSetupAnswer)answer;
-                    if (an.get_dir() != null) {
-                        // update the parent path in image_store table for this image store
-                        ImageStoreVO svo = _imageStoreDao.findById(ssStore.getId());
-                        svo.setParent(an.get_dir());
-                        _imageStoreDao.update(ssStore.getId(), svo);
-                    }
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
-                    }
-                } else {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
-                    }
-                    return false;
-                }
-            }
-        }
-        /* After removing SecondaryStorage entries from host table, control should never come here!!
-        else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
-            List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
-            String secUrl = cssHost.getStorageUrl();
-            SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
-            for ( SecondaryStorageVmVO ssVm : alreadyRunning ) {
-                HostVO host = _resourceMgr.findHostByName(ssVm.getInstanceName());
-                Answer answer = _agentMgr.easySend(host.getId(), setupCmd);
-                if (answer != null && answer.getResult()) {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
-                    }
-                } else {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
-                    }
-                    return false;
-                }
-            }
-        }
-         */
-        return true;
-    }
-
-    @Override
-    public boolean generateVMSetupCommand(Long ssAHostId) {
-        HostVO ssAHost = _hostDao.findById(ssAHostId);
-        if (ssAHost.getType() != Host.Type.SecondaryStorageVM) {
-            return false;
-        }
-        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
-        if (secStorageVm == null) {
-            s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
-            return false;
-        }
-
-        SecStorageVMSetupCommand setupCmd = new SecStorageVMSetupCommand();
-        if (_allowedInternalSites != null) {
-            List<String> allowedCidrs = new ArrayList<String>();
-            String[] cidrs = _allowedInternalSites.split(",");
-            for (String cidr : cidrs) {
-                if (NetUtils.isValidCIDR(cidr) || NetUtils.isValidIp(cidr) || !cidr.startsWith("0.0.0.0")) {
-                    allowedCidrs.add(cidr);
-                }
-            }
-            List<? extends Nic> nics = _networkModel.getNicsForTraffic(secStorageVm.getId(), TrafficType.Management);
-            setupCmd.setAllowedInternalSites(allowedCidrs.toArray(new String[allowedCidrs.size()]));
-        }
-        String copyPasswd = _configDao.getValue("secstorage.copy.password");
-        setupCmd.setCopyPassword(copyPasswd);
-        setupCmd.setCopyUserName(TemplateConstants.DEFAULT_HTTP_AUTH_USER);
-        Answer answer = _agentMgr.easySend(ssAHostId, setupCmd);
-        if (answer != null && answer.getResult()) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Successfully programmed http auth into " + secStorageVm.getHostName());
-            }
-            return true;
-        } else {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("failed to program http auth into secondary storage vm : " + secStorageVm.getHostName());
-            }
-            return false;
-        }
-    }
-
-    @Override
-    public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
-        return null;
-    }
-
-    @Override
-    public boolean generateFirewallConfiguration(Long ssAHostId) {
-        if (ssAHostId == null) {
-            return true;
-        }
-        HostVO ssAHost = _hostDao.findById(ssAHostId);
-        SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
-
-        if (thisSecStorageVm == null) {
-            s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
-            return false;
-        }
-
-        String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
-        SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
-        thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
-
-        QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
-        sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
-        sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
-        List<HostVO> ssvms = sc.list();
-        for (HostVO ssvm : ssvms) {
-            if (ssvm.getId() == ssAHostId) {
-                continue;
-            }
-            Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
-            if (answer != null && answer.getResult()) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
-                }
-            } else {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
-                }
-                return false;
-            }
-        }
-
-        SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
-        for (HostVO ssvm : ssvms) {
-            if (ssvm.getId() == ssAHostId) {
-                continue;
-            }
-            allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
-        }
-
-        Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
-        if (answer != null && answer.getResult()) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
-            }
-        } else {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
-            }
-            return false;
-        }
-
-        return true;
-
-    }
-
-    protected boolean isSecondaryStorageVmRequired(long dcId) {
-        DataCenterVO dc = _dcDao.findById(dcId);
-        _dcDao.loadDetails(dc);
-        String ssvmReq = dc.getDetail(ZoneConfig.EnableSecStorageVm.key());
-        if (ssvmReq != null) {
-            return Boolean.parseBoolean(ssvmReq);
-        }
-        return true;
-    }
-
-    public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role role) {
-
-        if (!isSecondaryStorageVmRequired(dataCenterId)) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
-            }
-            return null;
-        }
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Assign secondary storage vm from a newly started instance for request from data center : " + dataCenterId);
-        }
-
-        Map<String, Object> context = createSecStorageVmInstance(dataCenterId, role);
-
-        long secStorageVmId = (Long)context.get("secStorageVmId");
-        if (secStorageVmId == 0) {
-            if (s_logger.isTraceEnabled()) {
-                s_logger.trace("Creating secondary storage vm instance failed, data center id : " + dataCenterId);
-            }
-
-            return null;
-        }
-
-        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
-        // SecondaryStorageVmVO secStorageVm =
-        // allocSecStorageVmStorage(dataCenterId, secStorageVmId);
-        if (secStorageVm != null) {
-            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
-                new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATED, dataCenterId, secStorageVmId, secStorageVm, null));
-            return secStorageVm;
-        } else {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: " +
-                    secStorageVmId);
-            }
-
-            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
-                new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage"));
-        }
-        return null;
-    }
-
-    protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, SecondaryStorageVm.Role role) {
-        DataStore secStore = _dataStoreMgr.getImageStore(dataCenterId);
-        if (secStore == null) {
-            String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
-            s_logger.warn(msg);
-            throw new CloudRuntimeException(msg);
-        }
-
-        long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
-        String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
-        Account systemAcct = _accountMgr.getSystemAccount();
-
-        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
-        DataCenter dc = _dcDao.findById(plan.getDataCenterId());
-
-        NetworkVO defaultNetwork = null;
-        if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
-            List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
-            if (networks == null || networks.size() == 0) {
-                throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
-            }
-            defaultNetwork = networks.get(0);
-        } else {
-            TrafficType defaultTrafficType = TrafficType.Public;
-
-            if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
-                defaultTrafficType = TrafficType.Guest;
-            }
-            List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
-            // api should never allow this situation to happen
-            if (defaultNetworks.size() != 1) {
-                throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
-            }
-            defaultNetwork = defaultNetworks.get(0);
-        }
-
-        List<? extends NetworkOffering> offerings =
-            _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork,
-                NetworkOffering.SystemStorageNetwork);
-        LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(offerings.size() + 1);
-        NicProfile defaultNic = new NicProfile();
-        defaultNic.setDefaultNic(true);
-        defaultNic.setDeviceId(2);
-        try {
-            networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0),
-                defaultNic);
-            for (NetworkOffering offering : offerings) {
-                networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null);
-            }
-        } catch (ConcurrentOperationException e) {
-            s_logger.info("Unable to setup due to concurrent operation. " + e);
-            return new HashMap<String, Object>();
-        }
-
-        VMTemplateVO template = null;
-        HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
-        template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
-        if (template == null) {
-            throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
-        }
-
-        SecondaryStorageVmVO secStorageVm =
-            new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
-                systemAcct.getDomainId(), systemAcct.getId(), role, _serviceOffering.getOfferHA());
-        secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
-        secStorageVm = _secStorageVmDao.persist(secStorageVm);
-        try {
-            _itMgr.allocate(name, template, _serviceOffering, networks, plan, null);
-            secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
-        } catch (InsufficientCapacityException e) {
-            s_logger.warn("InsufficientCapacity", e);
-            throw new CloudRuntimeException("Insufficient capacity exception", e);
-        }
-
-        Map<String, Object> context = new HashMap<String, Object>();
-        context.put("secStorageVmId", secStorageVm.getId());
-        return context;
-    }
-
-    private SecondaryStorageVmAllocator getCurrentAllocator() {
-
-        // for now, only one adapter is supported
-        if (_ssVmAllocators.size() > 0) {
-            return _ssVmAllocators.get(0);
-        }
-
-        return null;
-    }
-
-    protected String connect(String ipAddress, int port) {
-        return null;
-    }
-
-    public SecondaryStorageVmVO assignSecStorageVmFromRunningPool(long dataCenterId, SecondaryStorageVm.Role role) {
-
-        if (s_logger.isTraceEnabled()) {
-            s_logger.trace("Assign  secondary storage vm from running pool for request from data center : " + dataCenterId);
-        }
-
-        SecondaryStorageVmAllocator allocator = getCurrentAllocator();
-        assert (allocator != null);
-        List<SecondaryStorageVmVO> runningList = _secStorageVmDao.getSecStorageVmListInStates(role, dataCenterId, State.Running);
-        if (runningList != null && runningList.size() > 0) {
-            if (s_logger.isTraceEnabled()) {
-                s_logger.trace("Running secondary storage vm pool size : " + runningList.size());
-                for (SecondaryStorageVmVO secStorageVm : runningList) {
-                    s_logger.trace("Running secStorageVm instance : " + secStorageVm.getHostName());
-                }
-            }
-
-            Map<Long, Integer> loadInfo = new HashMap<Long, Integer>();
-
-            return allocator.allocSecondaryStorageVm(runningList, loadInfo, dataCenterId);
-        } else {
-            if (s_logger.isTraceEnabled()) {
-                s_logger.trace("Empty running secStorageVm pool for now in data center : " + dataCenterId);
-            }
-        }
-        return null;
-    }
-
-    public SecondaryStorageVmVO assignSecStorageVmFromStoppedPool(long dataCenterId, SecondaryStorageVm.Role role) {
-        List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates(role, dataCenterId, State.Starting, State.Stopped, State.Migrating);
-        if (l != null && l.size() > 0) {
-            return l.get(0);
-        }
-
-        return null;
-    }
-
-    private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
-        if (s_logger.isTraceEnabled()) {
-            s_logger.trace("Allocate secondary storage vm standby capacity for data center : " + dataCenterId);
-        }
-
-        if (!isSecondaryStorageVmRequired(dataCenterId)) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
-            }
-            return;
-        }
-
-        boolean secStorageVmFromStoppedPool = false;
-        SecondaryStorageVmVO secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
-        if (secStorageVm == null) {
-            if (s_logger.isInfoEnabled()) {
-                s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm");
-            }
-
-            if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
-                try {
-                    secStorageVm = startNew(dataCenterId, role);
-                    for (UploadVO upload : _uploadDao.listAll()) {
-                        _uploadDao.expunge(upload.getId());
-                    }
-                } finally {
-                    _allocLock.unlock();
-                }
-            } else {
-                if (s_logger.isInfoEnabled()) {
-                    s_logger.info("Unable to acquire synchronization lock to allocate secStorageVm resource for standby capacity, wait for next scan");
-                }
-                return;
-            }
-        } else {
-            if (s_logger.isInfoEnabled()) {
-                s_logger.info("Found a stopped secondary storage vm, bring it up to running pool. secStorageVm vm id : " + secStorageVm.getId());
-            }
-            secStorageVmFromStoppedPool = true;
-        }
-
-        if (secStorageVm != null) {
-            long secStorageVmId = secStorageVm.getId();
-            GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
-            try {
-                if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
-                    try {
-                        secStorageVm = startSecStorageVm(secStorageVmId);
-                    } finally {
-                        secStorageVmLock.unlock();
-                    }
-                } else {
-                    if (s_logger.isInfoEnabled()) {
-                        s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId());
-                    }
-                    return;
-                }
-            } finally {
-                secStorageVmLock.releaseRef();
-            }
-
-            if (secStorageVm == null) {
-                if (s_logger.isInfoEnabled()) {
-                    s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId +
-                        ", will recycle it and start a new one");
-                }
-
-                if (secStorageVmFromStoppedPool) {
-                    destroySecStorageVm(secStorageVmId);
-                }
-            } else {
-                if (s_logger.isInfoEnabled()) {
-                    s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
-                }
-            }
-        }
-    }
-
-    public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
-        ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
-        if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) {
-            VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
-            if (template == null) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
-                }
-                return false;
-            }
-
-            List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
-            if (stores.size() < 1) {
-                s_logger.debug("No image store added  in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
-                return false;
-            }
-
-            DataStore store = templateMgr.getImageStore(dataCenterId, template.getId());
-            if (store == null) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("No secondary storage available in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
-                }
-                return false;
-            }
-
-            List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !_useLocalStorage);
-            if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
-                return true;
-            } else {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Primary storage is not ready, wait until it is ready to launch secondary storage vm. dcId: " + dataCenterId +
-                        " system.vm.use.local.storage: " + _useLocalStorage +
-                        "If you want to use local storage to start ssvm, need to set system.vm.use.local.storage to true");
-                }
-            }
-
-        }
-        return false;
-    }
-
-    private synchronized Map<Long, ZoneHostInfo> getZoneHostInfo() {
-        Date cutTime = DateUtil.currentGMTTime();
-        List<RunningHostCountInfo> l = _hostDao.getRunningHostCounts(new Date(cutTime.getTime() - ClusterManager.HeartbeatThreshold.value()));
-
-        RunningHostInfoAgregator aggregator = new RunningHostInfoAgregator();
-        if (l.size() > 0) {
-            for (RunningHostCountInfo countInfo : l) {
-                aggregator.aggregate(countInfo);
-            }
-        }
-
-        return aggregator.getZoneHostInfoMap();
-    }
-
-    @Override
-    public boolean start() {
-        if (s_logger.isInfoEnabled()) {
-            s_logger.info("Start secondary storage vm manager");
-        }
-
-        return true;
-    }
-
-    @Override
-    public boolean stop() {
-        _loadScanner.stop();
-        _allocLock.releaseRef();
-        _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
-        return true;
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        if (s_logger.isInfoEnabled()) {
-            s_logger.info("Start configuring secondary storage vm manager : " + name);
-        }
-
-        Map<String, String> configs = _configDao.getConfiguration("management-server", params);
-
-        _secStorageVmMtuSize = NumbersUtil.parseInt(configs.get("secstorage.vm.mtu.size"), DEFAULT_SS_VM_MTUSIZE);
-        String useServiceVM = _configDao.getValue("secondary.storage.vm");
-        boolean _useServiceVM = false;
-        if ("true".equalsIgnoreCase(useServiceVM)) {
-            _useServiceVM = true;
-        }
-
-        String sslcopy = _configDao.getValue("secstorage.encrypt.copy");
-        if ("true".equalsIgnoreCase(sslcopy)) {
-            _useSSlCopy = true;
-        }
-
-        _allowedInternalSites = _configDao.getValue("secstorage.allowed.internal.sites");
-
-        String value = configs.get("secstorage.capacityscan.interval");
-        _capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL);
-
-        _instance = configs.get("instance.name");
-        if (_instance == null) {
-            _instance = "DEFAULT";
-        }
-
-        Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
-
-        value = agentMgrConfigs.get("port");
-        _mgmtPort = NumbersUtil.parseInt(value, 8250);
-
-        _listener = new SecondaryStorageListener(this);
-        _agentMgr.registerForHostEvents(_listener, true, false, true);
-
-        _itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);
-
-        //check if there is a default service offering configured
-        String ssvmSrvcOffIdStr = configs.get(Config.SecondaryStorageServiceOffering.key());
-        if (ssvmSrvcOffIdStr != null) {
-            Long ssvmSrvcOffId = Long.parseLong(ssvmSrvcOffIdStr);
-            _serviceOffering = _offeringDao.findById(ssvmSrvcOffId);
-            if (_serviceOffering == null || !_serviceOffering.getSystemUse()) {
-                String msg = "Can't find system service offering id=" + ssvmSrvcOffId + " for secondary storage vm";
-                s_logger.error(msg);
-                throw new ConfigurationException(msg);
-            }
-        } else {
-            int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE);
-            int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ);
-            _useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
-            _serviceOffering =
-                new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, ramSize, cpuFreq, null, null, false, null, _useLocalStorage, true, null, true,
-                    VirtualMachine.Type.SecondaryStorageVm, true);
-            _serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName);
-            _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
-
-            // this can sometimes happen, if DB is manually or programmatically manipulated
-            if (_serviceOffering == null) {
-                String msg = "Data integrity problem : System Offering For Secondary Storage VM has been removed?";
-                s_logger.error(msg);
-                throw new ConfigurationException(msg);
-            }
-        }
-
-        if (_useServiceVM) {
-            _loadScanner = new SystemVmLoadScanner<Long>(this);
-            _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval);
-        }
-
-        _httpProxy = configs.get(Config.SecStorageProxy.key());
-        if (_httpProxy != null) {
-            boolean valid = true;
-            String errMsg = null;
-            try {
-                URI uri = new URI(_httpProxy);
-                if (!"http".equalsIgnoreCase(uri.getScheme())) {
-                    errMsg = "Only support http proxy";
-                    valid = false;
-                } else if (uri.getHost() == null) {
-                    errMsg = "host can not be null";
-                    valid = false;
-                } else if (uri.getPort() == -1) {
-                    _httpProxy = _httpProxy + ":3128";
-                }
-            } catch (URISyntaxException e) {
-                errMsg = e.toString();
-            } finally {
-                if (!valid) {
-                    s_logger.debug("ssvm http proxy " + _httpProxy + " is invalid: " + errMsg);
-                    throw new ConfigurationException("ssvm http proxy " + _httpProxy + "is invalid: " + errMsg);
-                }
-            }
-        }
-        if (s_logger.isInfoEnabled()) {
-            s_logger.info("Secondary storage vm Manager is configured.");
-        }
-        _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
-        return true;
-    }
-
-    @Override
-    public boolean stopSecStorageVm(long secStorageVmId) {
-        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
-        if (secStorageVm == null) {
-            String msg = "Stopping secondary storage vm failed: secondary storage vm " + secStorageVmId + " no longer exists";
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug(msg);
-            }
-            return false;
-        }
-        try {
-            if (secStorageVm.getHostId() != null) {
-                GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
-                try {
-                    if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
-                        try {
-                            _itMgr.stop(secStorageVm.getUuid());
-                            return true;
-                        } finally {
-                            secStorageVmLock.unlock();
-                        }
-                    } else {
-                        String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
-                        s_logger.debug(msg);
-                        return false;
-                    }
-                } finally {
-                    secStorageVmLock.releaseRef();
-                }
-            }
-
-            // vm was already stopped, return true
-            return true;
-        } catch (ResourceUnavailableException e) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Stopping secondary storage vm " + secStorageVm.getHostName() + " faled : exception " + e.toString());
-            }
-            return false;
-        }
-    }
-
-    @Override
-    public boolean rebootSecStorageVm(long secStorageVmId) {
-        final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
-
-        if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
-            return false;
-        }
-
-        if (secStorageVm.getState() == State.Running && secStorageVm.getHostId() != null) {
-            final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName());
-            final Answer answer = _agentMgr.easySend(secStorageVm.getHostId(), cmd);
-
-            if (answer != null && answer.getResult()) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
-                }
-
-                SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
-                    new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
-
-                return true;
-            } else {
-                String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug(msg);
-                }
-                return false;
-            }
-        } else {
-            return startSecStorageVm(secStorageVmId) != null;
-        }
-    }
-
-    @Override
-    public boolean destroySecStorageVm(long vmId) {
-        SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
-
-        try {
-            _itMgr.expunge(ssvm.getUuid());
-            _secStorageVmDao.remove(ssvm.getId());
-            HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(), Host.Type.SecondaryStorageVM);
-            if (host != null) {
-                s_logger.debug("Removing host entry for ssvm id=" + vmId);
-                _hostDao.remove(host.getId());
-            }
-
-            return true;
-        } catch (ResourceUnavailableException e) {
-            s_logger.warn("Unable to expunge " + ssvm, e);
-            return false;
-        }
-    }
-
-    @Override
-    public void onAgentConnect(Long dcId, StartupCommand cmd) {
-    }
-
-    private String getAllocLockName() {
-        // to improve security, it may be better to return a unique mashed
-        // name(for example MD5 hashed)
-        return "secStorageVm.alloc";
-    }
-
-    private String getSecStorageVmLockName(long id) {
-        return "secStorageVm." + id;
-    }
-
-    @Override
-    public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
-
-        SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId());
-        Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
-        vm.setDetails(details);
-
-        DataStore secStore = _dataStoreMgr.getImageStore(dest.getDataCenter().getId());
-        assert (secStore != null);
-
-        StringBuilder buf = profile.getBootArgsBuilder();
-        buf.append(" template=domP type=secstorage");
-        buf.append(" host=").append(ApiServiceConfiguration.ManagementHostIPAdr.value());
-        buf.append(" port=").append(_mgmtPort);
-        buf.append(" name=").append(profile.getVirtualMachine().getHostName());
-
-        buf.append(" zone=").append(dest.getDataCenter().getId());
-        buf.append(" pod=").append(dest.getPod().getId());
-
-        buf.append(" guid=").append(profile.getVirtualMachine().getHostName());
-
-        if (_configDao.isPremium()) {
-            s_logger.debug("VmWare hypervisor configured, telling the ssvm to load the PremiumSecondaryStorageResource");
-            buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource");
-        } else {
-            buf.append(" resource=org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource");
-        }
-        buf.append(" instance=SecStorage");
-        buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy));
-        buf.append(" role=").append(vm.getRole().toString());
-        buf.append(" mtu=").append(_secStorageVmMtuSize);
-
-        boolean externalDhcp = false;
-        String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
-        if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
-            externalDhcp = true;
-        }
-
-        if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
-            buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
-        }
-
-        for (NicProfile nic : profile.getNics()) {
-            int deviceId = nic.getDeviceId();
-            if (nic.getIp4Address() == null) {
-                buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0");
-                buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
-            } else {
-                buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
-                buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
-            }
-
-            if (nic.isDefaultNic()) {
-                buf.append(" gateway=").append(nic.getGateway());
-            }
-            if (nic.getTrafficType() == TrafficType.Management) {
-                String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key());
-                if (NetUtils.isValidCIDR(mgmt_cidr)) {
-                    buf.append(" mgmtcidr=").append(mgmt_cidr);
-                }
-                buf.append(" localgw=").append(dest.getPod().getGateway());
-                buf.append(" private.network.device=").append("eth").append(deviceId);
-            } else if (nic.getTrafficType() == TrafficType.Public) {
-                buf.append(" public.network.device=").append("eth").append(deviceId);
-            } else if (nic.getTrafficType() == TrafficType.Storage) {
-                buf.append(" storageip=").append(nic.getIp4Address());
-                buf.append(" storagenetmask=").append(nic.getNetmask());
-                buf.append(" storagegateway=").append(nic.getGateway());
-            }
-        }
-
-        /* External DHCP mode */
-        if (externalDhcp) {
-            buf.append(" bootproto=dhcp");
-        }
-
-        DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
-        buf.append(" internaldns1=").append(dc.getInternalDns1());
-        if (dc.getInternalDns2() != null) {
-            buf.append(" internaldns2=").append(dc.getInternalDns2());
-        }
-        buf.append(" dns1=").append(dc.getDns1());
-        if (dc.getDns2() != null) {
-            buf.append(" dns2=").append(dc.getDns2());
-        }
-
-        String bootArgs = buf.toString();
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
-        }
-
-        return true;
-    }
-
-    @Override
-    public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
-
-        finalizeCommandsOnStart(cmds, profile);
-
-        SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
-        DataCenter dc = dest.getDataCenter();
-        List<NicProfile> nics = profile.getNics();
-        for (NicProfile nic : nics) {
-            if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) ||
-                (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
-                secVm.setPublicIpAddress(nic.getIp4Address());
-                secVm.setPublicNetmask(nic.getNetmask());
-                secVm.setPublicMacAddress(nic.getMacAddress());
-            } else if (nic.getTrafficType() == TrafficType.Management) {
-                secVm.setPrivateIpAddress(nic.getIp4Address());
-                secVm.setPrivateMacAddress(nic.getMacAddress());
-            }
-        }
-        _secStorageVmDao.update(secVm.getId(), secVm);
-        return true;
-    }
-
-    @Override
-    public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) {
-
-        NicProfile managementNic = null;
-        NicProfile controlNic = null;
-        for (NicProfile nic : profile.getNics()) {
-            if (nic.getTrafficType() == TrafficType.Management) {
-                managementNic = nic;
-            } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
-                controlNic = nic;
-            }
-        }
-
-        if (controlNic == null) {
-            if (managementNic == null) {
-                s_logger.error("Management network doesn't exist for the secondaryStorageVm " + profile.getVirtualMachine());
-                return false;
-            }
-            controlNic = managementNic;
-        }
-
-        // verify ssh access on management nic for system vm running on HyperV
-        if(profile.getHypervisorType() == HypervisorType.Hyperv) {
-            controlNic = managementNic;
-        }
-
-        CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922);
-        cmds.addCommand("checkSsh", check);
-
-        return true;
-    }
-
-    @Override
-    public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) {
-        CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh");
-        if (!answer.getResult()) {
-            s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
-            return false;
-        }
-
-        try {
-            //get system ip and create static nat rule for the vm in case of basic networking with EIP/ELB
-            _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
-            IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId());
-            if (ipaddr != null && ipaddr.getSystem()) {
-                SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
-                // override SSVM guest IP with EIP, so that download url's with be prepared with EIP
-                secVm.setPublicIpAddress(ipaddr.getAddress().addr());
-                _secStorageVmDao.update(secVm.getId(), secVm);
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
-            return false;
-        }
-
-        return true;
-    }
-
-    @Override
-    public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
-        //release elastic IP here
-        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
-        if (ip != null && ip.getSystem()) {
-            CallContext ctx = CallContext.current();
-            try {
-                _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
-            } catch (Exception ex) {
-                s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ",
-                    ex);
-            }
-        }
-    }
-
-    @Override
-    public void finalizeExpunge(VirtualMachine vm) {
-        SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid());
-
-        ssvm.setPublicIpAddress(null);
-        ssvm.setPublicMacAddress(null);
-        ssvm.setPublicNetmask(null);
-        _secStorageVmDao.update(ssvm.getId(), ssvm);
-    }
-
-    @Override
-    public String getScanHandlerName() {
-        return "secstorage";
-    }
-
-    @Override
-    public boolean canScan() {
-        return true;
-    }
-
-    @Override
-    public void onScanStart() {
-        _zoneHostInfoMap = getZoneHostInfo();
-    }
-
-    @Override
-    public Long[] getScannablePools() {
-        List<DataCenterVO> zones = _dcDao.listEnabledZones();
-
-        Long[] dcIdList = new Long[zones.size()];
-        int i = 0;
-        for (DataCenterVO dc : zones) {
-            dcIdList[i++] = dc.getId();
-        }
-
-        return dcIdList;
-    }
-
-    @Override
-    public boolean isPoolReadyForScan(Long pool) {
-        // pool is at zone basis
-        long dataCenterId = pool.longValue();
-
-        if (!isZoneReady(_zoneHostInfoMap, dataCenterId)) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Zone " + dataCenterId + " is not ready to launch secondary storage VM yet");
-            }
-            return false;
-        }
-
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Zone " + dataCenterId + " is ready to launch secondary storage VM");
-        }
-        return true;
-    }
-
-    @Override
-    public Pair<AfterScanAction, Object> scanPool(Long pool) {
-        long dataCenterId = pool.longValue();
-
-        List<SecondaryStorageVmVO> ssVms =
-            _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting,
-                State.Stopped, State.Stopping);
-        int vmSize = (ssVms == null) ? 0 : ssVms.size();
-        List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
-        int storeSize = (ssStores == null) ? 0 : ssStores.size();
-        if (storeSize > vmSize) {
-            s_logger.info("No secondary storage vms found in datacenter id=" + dataCenterId + ", starting a new one");
-            return new Pair<AfterScanAction, Object>(AfterScanAction.expand, SecondaryStorageVm.Role.templateProcessor);
-        }
-
-        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, SecondaryStorageVm.Role.templateProcessor);
-    }
-
-    @Override
-    public void expandPool(Long pool, Object actionArgs) {
-        long dataCenterId = pool.longValue();
-        allocCapacity(dataCenterId, (SecondaryStorageVm.Role)actionArgs);
-    }
-
-    @Override
-    public void shrinkPool(Long pool, Object actionArgs) {
-    }
-
-    @Override
-    public void onScanEnd() {
-    }
-
-    @Override
-    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
-        /* Called when Secondary Storage VM connected */
-        StartupCommand firstCmd = cmd[0];
-        if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
-            return null;
-        }
-
-        host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
-        return host;
-    }
-
-    @Override
-    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
-        // Used to be Called when add secondary storage on UI through DummySecondaryStorageResource to update that host entry for Secondary Storage.
-        // Now since we move secondary storage from host table, this code is not needed to be invoked anymore.
-        /*
-        StartupCommand firstCmd = startup[0];
-        if (!(firstCmd instanceof StartupStorageCommand)) {
-            return null;
-        }
-
-        com.cloud.host.Host.Type type = null;
-        StartupStorageCommand ssCmd = ((StartupStorageCommand) firstCmd);
-        if (ssCmd.getHostType() == Host.Type.SecondaryStorageCmdExecutor) {
-            type = ssCmd.getHostType();
-        } else {
-            if (ssCmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) {
-                type = Host.Type.SecondaryStorage;
-                if (resource != null && resource instanceof DummySecondaryStorageResource) {
-                    host.setResource(null);
-                }
-            } else if (ssCmd.getResourceType() == Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE) {
-                type = Host.Type.LocalSecondaryStorage;
-            } else {
-                type = Host.Type.Storage;
-            }
-
-            final Map<String, String> hostDetails = ssCmd.getHostDetails();
-            if (hostDetails != null) {
-                if (details != null) {
-                    details.putAll(hostDetails);
-                } else {
-                    details = hostDetails;
-                }
-            }
-
-            host.setDetails(details);
-            host.setParent(ssCmd.getParent());
-            host.setTotalSize(ssCmd.getTotalSize());
-            host.setHypervisorType(HypervisorType.None);
-            host.setType(type);
-            if (ssCmd.getNfsShare() != null) {
-                host.setStorageUrl(ssCmd.getNfsShare());
-            }
-        }
-         */
-        return null; // no need to handle this event anymore since secondary storage is not in host table anymore.
-    }
-
-    @Override
-    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
-        // Since secondary storage is moved out of host table, this class should not handle delete secondary storage anymore.
-        return null;
-    }
-
-    @Override
-    public List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
-        QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
-        if (dcId != null) {
-            sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId);
-        }
-        sc.and(sc.entity().getState(), Op.IN, Status.Up, Status.Connecting);
-        sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
-        return sc.list();
-    }
-
-    @Override
-    public HostVO pickSsvmHost(HostVO ssHost) {
-        if (ssHost.getType() == Host.Type.LocalSecondaryStorage) {
-            return ssHost;
-        } else if (ssHost.getType() == Host.Type.SecondaryStorage) {
-            Long dcId = ssHost.getDataCenterId();
-            List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
-            if (ssAHosts == null || ssAHosts.isEmpty()) {
-                return null;
-            }
-            Collections.shuffle(ssAHosts);
-            return ssAHosts.get(0);
-        }
-        return null;
-    }
-
-    @Override
-    public void prepareStop(VirtualMachineProfile profile) {
-
-    }
-
-    public List<SecondaryStorageVmAllocator> getSecondaryStorageVmAllocators() {
-        return _ssVmAllocators;
-    }
-
-    @Inject
-    public void setSecondaryStorageVmAllocators(List<SecondaryStorageVmAllocator> ssVmAllocators) {
-        _ssVmAllocators = ssVmAllocators;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java
index 4a02968..06f21d3 100644
--- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java
+++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java
@@ -41,6 +41,7 @@ public class ConsoleProxyThumbnailHandler implements HttpHandler {
     }
 
     @Override
+    @SuppressWarnings("access")
     public void handle(HttpExchange t) throws IOException {
         try {
             Thread.currentThread().setName("JPG Thread " + Thread.currentThread().getId() + " " + t.getRemoteAddress());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/services/secondary-storage/controller/resources/META-INF/cloudstack/core/spring-services-secondary-storage-controller-core-context.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/resources/META-INF/cloudstack/core/spring-services-secondary-storage-controller-core-context.xml b/services/secondary-storage/controller/resources/META-INF/cloudstack/core/spring-services-secondary-storage-controller-core-context.xml
new file mode 100644
index 0000000..a62fede
--- /dev/null
+++ b/services/secondary-storage/controller/resources/META-INF/cloudstack/core/spring-services-secondary-storage-controller-core-context.xml
@@ -0,0 +1,33 @@
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/context
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+                      >
+    <bean id="premiumSecondaryStorageManagerImpl" class="org.apache.cloudstack.secondarystorage.PremiumSecondaryStorageManagerImpl">
+            <property name="secondaryStorageVmAllocators"
+            value="#{secondaryStorageVmAllocatorsRegistry.registered}" />
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54f32a8e/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/PremiumSecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/PremiumSecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/PremiumSecondaryStorageManagerImpl.java
new file mode 100755
index 0000000..af96ed2
--- /dev/null
+++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/PremiumSecondaryStorageManagerImpl.java
@@ -0,0 +1,186 @@
+// 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.secondarystorage;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Command;
+import com.cloud.configuration.Config;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.host.dao.HostDao;
+import com.cloud.resource.ResourceManager;
+import com.cloud.secstorage.CommandExecLogDao;
+import com.cloud.secstorage.CommandExecLogVO;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.vm.SecondaryStorageVm;
+import com.cloud.vm.SecondaryStorageVmVO;
+import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
+import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.dao.SecondaryStorageVmDao;
+
+@Local(value = {SecondaryStorageVmManager.class})
+public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerImpl {
+    private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageManagerImpl.class);
+
+    private int _capacityPerSSVM = SecondaryStorageVmManager.DEFAULT_SS_VM_CAPACITY;
+    private int _standbyCapacity = SecondaryStorageVmManager.DEFAULT_STANDBY_CAPACITY;
+    private int _maxExecutionTimeMs = 1800000;
+
+    @Inject
+    SecondaryStorageVmDao _secStorageVmDao;
+    @Inject
+    CommandExecLogDao _cmdExecLogDao;
+    @Inject
+    HostDao _hostDao;
+    @Inject
+    ResourceManager _resourceMgr;
+    protected SearchBuilder<CommandExecLogVO> ActiveCommandSearch;
+    protected SearchBuilder<HostVO> HostSearch;
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        super.configure(name, params);
+
+        _capacityPerSSVM = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageSessionMax.key()), DEFAULT_SS_VM_CAPACITY);
+        _standbyCapacity = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageCapacityStandby.key()), DEFAULT_STANDBY_CAPACITY);
+
+        int nMaxExecutionMinutes = NumbersUtil.parseInt(_configDao.getValue(Config.SecStorageCmdExecutionTimeMax.key()), 30);
+        _maxExecutionTimeMs = nMaxExecutionMinutes * 60 * 1000;
+
+        HostSearch = _hostDao.createSearchBuilder();
+        HostSearch.and("dc", HostSearch.entity().getDataCenterId(), Op.EQ);
+        HostSearch.and("status", HostSearch.entity().getStatus(), Op.EQ);
+
+        ActiveCommandSearch = _cmdExecLogDao.createSearchBuilder();
+        ActiveCommandSearch.and("created", ActiveCommandSearch.entity().getCreated(), Op.GTEQ);
+        ActiveCommandSearch.join("hostSearch", HostSearch, ActiveCommandSearch.entity().getInstanceId(), HostSearch.entity().getId(), JoinType.INNER);
+
+        HostSearch.done();
+        ActiveCommandSearch.done();
+        return true;
+    }
+
+    @Override
+    public Pair<AfterScanAction, Object> scanPool(Long pool) {
+        long dataCenterId = pool.longValue();
+        if (!isSecondaryStorageVmRequired(dataCenterId)) {
+            return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
+        }
+
+        Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _maxExecutionTimeMs);
+
+        _cmdExecLogDao.expungeExpiredRecords(cutTime);
+
+        boolean suspendAutoLoading = !reserveStandbyCapacity();
+        if (!suspendAutoLoading) {
+            // this is a hacking, has nothing to do with console proxy, it is just a flag that primary storage is being under maintenance mode
+            String restart = _configDao.getValue("consoleproxy.restart");
+            if (restart != null && restart.equalsIgnoreCase("false")) {
+                s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode");
+                suspendAutoLoading = true;
+            }
+        }
+
+        List<SecondaryStorageVmVO> alreadyRunning =
+            _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting);
+        if (alreadyRunning.size() == 0) {
+            s_logger.info("No running secondary storage vms found in datacenter id=" + dataCenterId + ", starting one");
+
+            List<SecondaryStorageVmVO> stopped =
+                _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping);
+            if (stopped.size() == 0 || !suspendAutoLoading) {
+                List<SecondaryStorageVmVO> stopping = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Stopping);
+                if (stopping.size() > 0) {
+                    s_logger.info("Found SSVMs that are currently at stopping state, wait until they are settled");
+                    return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
+                }
+
+                expandPool(pool, SecondaryStorageVm.Role.templateProcessor);
+            }
+        }
+
+        if (!suspendAutoLoading) {
+            // this is to avoid surprises that people may accidently see two SSVMs being launched, capacity expanding only happens when we have at least the primary SSVM is up
+            if (alreadyRunning.size() == 0) {
+                s_logger.info("Primary secondary storage is not even started, wait until next turn");
+                return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
+            }
+
+            alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, dataCenterId, State.Running, State.Migrating, State.Starting);
+
+            List<CommandExecLogVO> activeCmds = listActiveCommands(dataCenterId, cutTime);
+            if (alreadyRunning.size() * _capacityPerSSVM - activeCmds.size() < _standbyCapacity) {
+                s_logger.info("secondary storage command execution standby capactiy low (running VMs: " + alreadyRunning.size() + ", active cmds: " + activeCmds.size() +
+                    "), starting a new one");
+                return new Pair<AfterScanAction, Object>(AfterScanAction.expand, SecondaryStorageVm.Role.commandExecutor);
+            }
+        }
+
+        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
+    }
+
+    @Override
+    public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
+
+        // TODO, need performance optimization
+        List<Long> vms = _secStorageVmDao.listRunningSecStorageOrderByLoad(null, zoneId);
+        for (Long vmId : vms) {
+            SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(vmId);
+            HostVO host;
+            host = _resourceMgr.findHostByName(secStorageVm.getHostName());
+            if (host != null && host.getStatus() == Status.Up)
+                return new Pair<HostVO, SecondaryStorageVmVO>(host, secStorageVm);
+        }
+
+        return null;
+    }
+
+    private List<CommandExecLogVO> listActiveCommands(long dcId, Date cutTime) {
+        SearchCriteria<CommandExecLogVO> sc = ActiveCommandSearch.create();
+
+        sc.setParameters("created", cutTime);
+        sc.setJoinParameters("hostSearch", "dc", dcId);
+        sc.setJoinParameters("hostSearch", "status", Status.Up);
+
+        return _cmdExecLogDao.search(sc, null);
+    }
+
+    private boolean reserveStandbyCapacity() {
+        String value = _configDao.getValue(Config.SystemVMAutoReserveCapacity.key());
+        if (value != null && value.equalsIgnoreCase("true")) {
+            return true;
+        }
+
+        return false;
+    }
+}


[28/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Detail view UI: Fix embedded list view actions

Fixes case when detail view has an embedded list view with action, that
the action is handled by detail view instead of list view, causing
unexpected behavior


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c2c7d33d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c2c7d33d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c2c7d33d

Branch: refs/heads/rbac
Commit: c2c7d33d8ec79a2e3fdb4736821e7708b843d658
Parents: a873a0e
Author: Brian Federle <br...@citrix.com>
Authored: Wed Feb 5 11:47:04 2014 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Wed Feb 5 11:47:04 2014 -0800

----------------------------------------------------------------------
 ui/scripts/ui/widgets/detailView.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2c7d33d/ui/scripts/ui/widgets/detailView.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/detailView.js b/ui/scripts/ui/widgets/detailView.js
index 9ca4ddd..4c5aeea 100644
--- a/ui/scripts/ui/widgets/detailView.js
+++ b/ui/scripts/ui/widgets/detailView.js
@@ -1486,7 +1486,8 @@
         }
 
         // Detail action
-        if ($target.closest('div.detail-view [detail-action], div.detail-view .action.text').size()) {
+        if ($target.closest('div.detail-view [detail-action], div.detail-view .action.text').size() &&
+            !$target.closest('.list-view').size()) {
             var $action = $target.closest('.action').find('[detail-action]');
             var actionName = $action.attr('detail-action');
             var actionCallback = $action.data('detail-view-action-callback');


[08/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Moved the secondary storage service into its own server directory


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4be3b993
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4be3b993
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4be3b993

Branch: refs/heads/rbac
Commit: 4be3b9933760c7713380112dff6f997cbe127def
Parents: aaa2094
Author: Alex Huang <al...@citrix.com>
Authored: Wed Jan 15 17:37:15 2014 -0800
Committer: Alex Huang <al...@citrix.com>
Committed: Wed Feb 5 01:38:24 2014 +0000

----------------------------------------------------------------------
 services/secondary-storage/controller/pom.xml   |   50 +
 services/secondary-storage/pom.xml              |   85 +-
 .../module.properties                           |   18 -
 ...ing-secondary-storage-discoverer-context.xml |   36 -
 services/secondary-storage/server/pom.xml       |  105 +
 .../module.properties                           |   18 +
 ...ing-secondary-storage-discoverer-context.xml |   36 +
 .../LocalNfsSecondaryStorageResource.java       |   95 +
 .../resource/LocalSecondaryStorageResource.java |  240 ++
 .../resource/NfsSecondaryStorageResource.java   | 2430 ++++++++++++++++++
 .../resource/SecondaryStorageDiscoverer.java    |  312 +++
 .../resource/SecondaryStorageResource.java      |   29 +
 .../SecondaryStorageResourceHandler.java        |   24 +
 .../storage/template/DownloadManager.java       |  108 +
 .../storage/template/DownloadManagerImpl.java   | 1080 ++++++++
 .../storage/template/UploadManager.java         |   82 +
 .../storage/template/UploadManagerImpl.java     |  550 ++++
 .../LocalNfsSecondaryStorageResourceTest.java   |  143 ++
 .../NfsSecondaryStorageResourceTest.java        |  110 +
 .../LocalNfsSecondaryStorageResource.java       |   95 -
 .../resource/LocalSecondaryStorageResource.java |  240 --
 .../resource/NfsSecondaryStorageResource.java   | 2430 ------------------
 .../resource/SecondaryStorageDiscoverer.java    |  312 ---
 .../resource/SecondaryStorageResource.java      |   29 -
 .../SecondaryStorageResourceHandler.java        |   24 -
 .../storage/template/DownloadManager.java       |  108 -
 .../storage/template/DownloadManagerImpl.java   | 1080 --------
 .../storage/template/UploadManager.java         |   82 -
 .../storage/template/UploadManagerImpl.java     |  550 ----
 .../LocalNfsSecondaryStorageResourceTest.java   |  143 --
 .../NfsSecondaryStorageResourceTest.java        |  110 -
 31 files changed, 5419 insertions(+), 5335 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/controller/pom.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/pom.xml b/services/secondary-storage/controller/pom.xml
new file mode 100644
index 0000000..47a730d
--- /dev/null
+++ b/services/secondary-storage/controller/pom.xml
@@ -0,0 +1,50 @@
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-controller-secondary-storage</artifactId>
+  <name>Apache CloudStack Secondary Storage Controller</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-service-secondary-storage</artifactId>
+    <version>4.4.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <dependencies>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-utils</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-server</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/pom.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/pom.xml b/services/secondary-storage/pom.xml
index 2798584..61077a0 100644
--- a/services/secondary-storage/pom.xml
+++ b/services/secondary-storage/pom.xml
@@ -18,88 +18,17 @@
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
-  <artifactId>cloud-secondary-storage</artifactId>
-  <name>Apache CloudStack Secondary Storage Service</name>
+  <artifactId>cloudstack-service-secondary-storage</artifactId>
+  <name>Apache CloudStack Secondary Storage</name>
+  <packaging>pom</packaging>
   <parent>
     <groupId>org.apache.cloudstack</groupId>
     <artifactId>cloudstack-services</artifactId>
     <version>4.4.0-SNAPSHOT</version>
     <relativePath>../pom.xml</relativePath>
   </parent>
-    <properties>
-    <skipTests>true</skipTests>
-  </properties>
-    <dependencies>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>com.google.code.gson</groupId>
-      <artifactId>gson</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-    </dependency>
-    <!-- required deps for the systemvm -->
-    <dependency>
-      <groupId>org.apache.cloudstack</groupId>
-      <artifactId>cloud-agent</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.cloudstack</groupId>
-      <artifactId>cloud-server</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-  </dependencies>
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-         <skipTests>${skipTests}</skipTests>
-         <systemPropertyVariables>
-            <log4j.configuration>file:${project.build.testSourceDirectory}/../conf/log4j.xml</log4j.configuration>
-        </systemPropertyVariables>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>exec-maven-plugin</artifactId>
-        <version>1.2.1</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>java</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <mainClass>com.cloud.agent.AgentShell</mainClass>
-          <arguments>
-            <argument>zone=1</argument>
-            <argument>pod=1</argument>
-            <argument>host=192.168.56.1</argument>
-            <argument>name=192.168.56.10</argument>
-            <argument>eth1ip=192.168.56.10</argument>
-            <argument>eth2ip=192.168.56.10</argument>
-            <argument>guid=SecondaryStorage.1</argument>
-            <argument>secondary.storage.vm=false</argument>
-            <argument>instance=Secondary</argument>
-          </arguments>
-          <systemProperties>
-            <systemProperty>
-              <key>javax.net.ssl.trustStore</key>
-              <value>certs/realhostip.keystore</value>
-              <key>log.home</key>
-              <value>${PWD}/</value>
-            </systemProperty>
-          </systemProperties>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+  <modules>
+    <module>controller</module>
+    <module>server</module>
+  </modules>
 </project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
----------------------------------------------------------------------
diff --git a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
deleted file mode 100644
index 7ff8a3a..0000000
--- a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
+++ /dev/null
@@ -1,18 +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.
-name=secondary-storage-discoverer
-parent=discoverer
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
deleted file mode 100644
index 30521aa..0000000
--- a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
+++ /dev/null
@@ -1,36 +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.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:context="http://www.springframework.org/schema/context"
-       xmlns:aop="http://www.springframework.org/schema/aop"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
-                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
-                      http://www.springframework.org/schema/context
-                      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
-                      >
-
-    <bean id="SecondaryStorageDiscoverer"
-        class="org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer">
-        <property name="name" value="SecondaryStorage" />
-    </bean>
-
-    
-</beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/pom.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/pom.xml b/services/secondary-storage/server/pom.xml
new file mode 100644
index 0000000..29fd7c7
--- /dev/null
+++ b/services/secondary-storage/server/pom.xml
@@ -0,0 +1,105 @@
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-secondary-storage</artifactId>
+  <name>Apache CloudStack Secondary Storage Service</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-service-secondary-storage</artifactId>
+    <version>4.4.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+    <properties>
+    <skipTests>true</skipTests>
+  </properties>
+    <dependencies>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <!-- required deps for the systemvm -->
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-agent</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-server</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+         <skipTests>${skipTests}</skipTests>
+         <systemPropertyVariables>
+            <log4j.configuration>file:${project.build.testSourceDirectory}/../conf/log4j.xml</log4j.configuration>
+        </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <version>1.2.1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>java</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <mainClass>com.cloud.agent.AgentShell</mainClass>
+          <arguments>
+            <argument>zone=1</argument>
+            <argument>pod=1</argument>
+            <argument>host=192.168.56.1</argument>
+            <argument>name=192.168.56.10</argument>
+            <argument>eth1ip=192.168.56.10</argument>
+            <argument>eth2ip=192.168.56.10</argument>
+            <argument>guid=SecondaryStorage.1</argument>
+            <argument>secondary.storage.vm=false</argument>
+            <argument>instance=Secondary</argument>
+          </arguments>
+          <systemProperties>
+            <systemProperty>
+              <key>javax.net.ssl.trustStore</key>
+              <value>certs/realhostip.keystore</value>
+              <key>log.home</key>
+              <value>${PWD}/</value>
+            </systemProperty>
+          </systemProperties>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties b/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
new file mode 100644
index 0000000..7ff8a3a
--- /dev/null
+++ b/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties
@@ -0,0 +1,18 @@
+# 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.
+name=secondary-storage-discoverer
+parent=discoverer
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml b/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
new file mode 100644
index 0000000..30521aa
--- /dev/null
+++ b/services/secondary-storage/server/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml
@@ -0,0 +1,36 @@
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/context
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+                      >
+
+    <bean id="SecondaryStorageDiscoverer"
+        class="org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer">
+        <property name="name" value="SecondaryStorage" />
+    </bean>
+
+    
+</beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.java
new file mode 100644
index 0000000..9393ee2
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResource.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.storage.resource;
+
+import java.net.URI;
+import java.util.concurrent.Executors;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.storage.JavaStorageLayer;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+@Component
+public class LocalNfsSecondaryStorageResource extends NfsSecondaryStorageResource {
+
+    private static final Logger s_logger = Logger.getLogger(LocalNfsSecondaryStorageResource.class);
+
+    public LocalNfsSecondaryStorageResource() {
+        this._dlMgr = new DownloadManagerImpl();
+        ((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
+        _storage = new JavaStorageLayer();
+        this._inSystemVM = false;
+    }
+
+    @Override
+    public void setParentPath(String path) {
+        this._parent = path;
+    }
+
+    @Override
+    public Answer executeRequest(Command cmd) {
+        return super.executeRequest(cmd);
+    }
+
+    @Override
+    synchronized public String getRootDir(String secUrl) {
+        try {
+            URI uri = new URI(secUrl);
+            String dir = mountUri(uri);
+            return _parent + "/" + dir;
+        } catch (Exception e) {
+            String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
+            s_logger.error(msg, e);
+            throw new CloudRuntimeException(msg);
+        }
+    }
+
+    @Override
+    protected void mount(String localRootPath, String remoteDevice, URI uri) {
+        ensureLocalRootPathExists(localRootPath, uri);
+
+        if (mountExists(localRootPath, uri)) {
+            return;
+        }
+
+        attemptMount(localRootPath, remoteDevice, uri);
+
+        // Change permissions for the mountpoint - seems to bypass authentication
+        Script script = new Script(true, "chmod", _timeout, s_logger);
+        script.add("777", localRootPath);
+        String result = script.execute();
+        if (result != null) {
+            String errMsg = "Unable to set permissions for " + localRootPath + " due to " + result;
+            s_logger.error(errMsg);
+            throw new CloudRuntimeException(errMsg);
+        }
+        s_logger.debug("Successfully set 777 permission for " + localRootPath);
+
+        // XXX: Adding the check for creation of snapshots dir here. Might have
+        // to move it somewhere more logical later.
+        checkForSnapshotsDir(localRootPath);
+        checkForVolumesDir(localRootPath);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
new file mode 100644
index 0000000..bdfe7e8
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/LocalSecondaryStorageResource.java
@@ -0,0 +1,240 @@
+// 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.storage.resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.command.DownloadProgressCommand;
+import org.apache.cloudstack.storage.template.DownloadManager;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckHealthAnswer;
+import com.cloud.agent.api.CheckHealthCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.ComputeChecksumCommand;
+import com.cloud.agent.api.PingCommand;
+import com.cloud.agent.api.PingStorageCommand;
+import com.cloud.agent.api.ReadyAnswer;
+import com.cloud.agent.api.ReadyCommand;
+import com.cloud.agent.api.SecStorageSetupCommand;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupStorageCommand;
+import com.cloud.agent.api.storage.ListTemplateAnswer;
+import com.cloud.agent.api.storage.ListTemplateCommand;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.host.Host;
+import com.cloud.host.Host.Type;
+import com.cloud.resource.ServerResourceBase;
+import com.cloud.storage.Storage;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.StorageLayer;
+import com.cloud.storage.template.TemplateProp;
+import com.cloud.utils.component.ComponentContext;
+
+public class LocalSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
+    private static final Logger s_logger = Logger.getLogger(LocalSecondaryStorageResource.class);
+    int _timeout;
+
+    String _instance;
+    String _parent;
+
+    String _dc;
+    String _pod;
+    String _guid;
+
+    StorageLayer _storage;
+
+    DownloadManager _dlMgr;
+
+    @Override
+    public void disconnected() {
+    }
+
+    @Override
+    public String getRootDir(String url) {
+        return getRootDir();
+
+    }
+
+    public String getRootDir() {
+        return _parent;
+    }
+
+    @Override
+    public Answer executeRequest(Command cmd) {
+        if (cmd instanceof DownloadProgressCommand) {
+            return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
+        } else if (cmd instanceof DownloadCommand) {
+            return _dlMgr.handleDownloadCommand(this, (DownloadCommand)cmd);
+        } else if (cmd instanceof CheckHealthCommand) {
+            return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
+        } else if (cmd instanceof SecStorageSetupCommand) {
+            return new Answer(cmd, true, "success");
+        } else if (cmd instanceof ReadyCommand) {
+            return new ReadyAnswer((ReadyCommand)cmd);
+        } else if (cmd instanceof ListTemplateCommand) {
+            return execute((ListTemplateCommand)cmd);
+        } else if (cmd instanceof ComputeChecksumCommand) {
+            return execute((ComputeChecksumCommand)cmd);
+        } else {
+            return Answer.createUnsupportedCommandAnswer(cmd);
+        }
+    }
+
+    private Answer execute(ComputeChecksumCommand cmd) {
+        return new Answer(cmd, false, null);
+    }
+
+    private Answer execute(ListTemplateCommand cmd) {
+        String root = getRootDir();
+        Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
+        return new ListTemplateAnswer(((NfsTO)cmd.getDataStore()).getUrl(), templateInfos);
+    }
+
+    @Override
+    public Type getType() {
+        return Host.Type.LocalSecondaryStorage;
+    }
+
+    @Override
+    public PingCommand getCurrentStatus(final long id) {
+        return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        super.configure(name, params);
+
+        _guid = (String)params.get("guid");
+        if (_guid == null) {
+            throw new ConfigurationException("Unable to find the guid");
+        }
+
+        _dc = (String)params.get("zone");
+        if (_dc == null) {
+            throw new ConfigurationException("Unable to find the zone");
+        }
+        _pod = (String)params.get("pod");
+
+        _instance = (String)params.get("instance");
+
+        _parent = (String)params.get("mount.path");
+        if (_parent == null) {
+            throw new ConfigurationException("No directory specified.");
+        }
+
+        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
+        if (_storage == null) {
+            String value = (String)params.get(StorageLayer.ClassConfigKey);
+            if (value == null) {
+                value = "com.cloud.storage.JavaStorageLayer";
+            }
+
+            try {
+                Class<StorageLayer> clazz = (Class<StorageLayer>)Class.forName(value);
+                _storage = ComponentContext.inject(clazz);
+            } catch (ClassNotFoundException e) {
+                throw new ConfigurationException("Unable to find class " + value);
+            }
+        }
+
+        if (!_storage.mkdirs(_parent)) {
+            s_logger.warn("Unable to create the directory " + _parent);
+            throw new ConfigurationException("Unable to create the directory " + _parent);
+        }
+
+        s_logger.info("Mount point established at " + _parent);
+
+        params.put("template.parent", _parent);
+        params.put(StorageLayer.InstanceConfigKey, _storage);
+
+        _dlMgr = new DownloadManagerImpl();
+        _dlMgr.configure("DownloadManager", params);
+
+        return true;
+    }
+
+    @Override
+    public boolean start() {
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        return true;
+    }
+
+    @Override
+    public StartupCommand[] initialize() {
+
+        final StartupStorageCommand cmd =
+            new StartupStorageCommand(_parent, StoragePoolType.Filesystem, 1024l * 1024l * 1024l * 1024l, _dlMgr.gatherTemplateInfo(_parent));
+        cmd.setResourceType(Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE);
+        cmd.setIqn("local://");
+        fillNetworkInformation(cmd);
+        cmd.setDataCenter(_dc);
+        cmd.setPod(_pod);
+        cmd.setGuid(_guid);
+        cmd.setName(_guid);
+        cmd.setVersion(LocalSecondaryStorageResource.class.getPackage().getImplementationVersion());
+
+        return new StartupCommand[] {cmd};
+    }
+
+    @Override
+    protected String getDefaultScriptsDir() {
+        return "scripts/storage/secondary";
+    }
+
+    @Override
+    public void setName(String name) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setConfigParams(Map<String, Object> params) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public Map<String, Object> getConfigParams() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public int getRunLevel() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setRunLevel(int level) {
+        // TODO Auto-generated method stub
+
+    }
+}


[16/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6030: Encrypt the primary and secondary smb storage password when it is stored in the db.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a24263fe
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a24263fe
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a24263fe

Branch: refs/heads/rbac
Commit: a24263fe81dc2a173bd06e8cec6bbe43c625e9e6
Parents: 0ce4888
Author: Devdeep Singh <de...@gmail.com>
Authored: Wed Feb 5 14:58:12 2014 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Wed Feb 5 15:44:09 2014 +0530

----------------------------------------------------------------------
 api/src/com/cloud/storage/Storage.java          |  5 +-
 .../storage/datastore/db/ImageStoreVO.java      | 10 +++-
 .../storage/datastore/db/StoragePoolVO.java     | 15 ++++-
 .../datastore/PrimaryDataStoreHelper.java       |  2 +-
 .../HypervResource/CloudStackTypes.cs           |  8 ++-
 .../HypervResource/HypervResourceController.cs  |  8 ++-
 ...CloudStackPrimaryDataStoreLifeCycleImpl.java |  8 +--
 utils/src/com/cloud/utils/UriUtils.java         | 60 ++++++++++++++++++++
 8 files changed, 100 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/api/src/com/cloud/storage/Storage.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java
index 2175c9b..ff83dfc 100755
--- a/api/src/com/cloud/storage/Storage.java
+++ b/api/src/com/cloud/storage/Storage.java
@@ -86,7 +86,7 @@ public class Storage {
 
     public static enum StoragePoolType {
         Filesystem(false), // local directory
-        NetworkFilesystem(true), // NFS or CIFS
+        NetworkFilesystem(true), // NFS
         IscsiLUN(true), // shared LUN, with a clusterfs overlay
         Iscsi(true), // for e.g., ZFS Comstar
         ISO(false), // for iso image
@@ -97,7 +97,8 @@ public class Storage {
         VMFS(true), // VMware VMFS storage
         PreSetup(true), // for XenServer, Storage Pool is set up by customers.
         EXT(false), // XenServer local EXT SR
-        OCFS2(true);
+        OCFS2(true),
+        SMB(true);
 
         boolean shared;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
index 77e50bd..36cc57c 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
@@ -31,6 +31,7 @@ import javax.persistence.TableGenerator;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.ImageStore;
 import com.cloud.storage.ScopeType;
+import com.cloud.utils.UriUtils;
 import com.cloud.utils.db.GenericDao;
 
 @Entity
@@ -149,11 +150,18 @@ public class ImageStoreVO implements ImageStore {
     }
 
     public String getUrl() {
-        return url;
+        String updatedUrl = url;
+        if ("cifs".equalsIgnoreCase(this.protocol)) {
+            updatedUrl = UriUtils.getUpdateUri(updatedUrl, false);
+        }
+        return updatedUrl;
     }
 
     public void setUrl(String url) {
         this.url = url;
+        if ("cifs".equalsIgnoreCase(this.protocol)) {
+            this.url = UriUtils.getUpdateUri(url, true);
+        }
     }
 
     public Date getCreated() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
index ede2b97..e1e21e1 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
@@ -34,6 +34,7 @@ import com.cloud.storage.ScopeType;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.StoragePool;
 import com.cloud.storage.StoragePoolStatus;
+import com.cloud.utils.UriUtils;
 import com.cloud.utils.db.GenericDao;
 
 @Entity
@@ -141,10 +142,10 @@ public class StoragePoolVO implements StoragePool {
         this.usedBytes = availableBytes;
         this.capacityBytes = capacityBytes;
         this.hostAddress = hostAddress;
-        this.path = hostPath;
         this.port = port;
         this.podId = podId;
         this.setStatus(StoragePoolStatus.Initial);
+        this.setPath(hostPath);
     }
 
     public StoragePoolVO(StoragePoolVO that) {
@@ -155,9 +156,9 @@ public class StoragePoolVO implements StoragePool {
         this.poolType = type;
         this.hostAddress = hostAddress;
         this.port = port;
-        this.path = path;
         this.setStatus(StoragePoolStatus.Initial);
         this.uuid = UUID.randomUUID().toString();
+        this.setPath(path);
     }
 
     @Override
@@ -262,7 +263,12 @@ public class StoragePoolVO implements StoragePool {
 
     @Override
     public String getPath() {
-        return path;
+        String updatedPath = path;
+        if (this.poolType == StoragePoolType.SMB) {
+            updatedPath = UriUtils.getUpdateUri(updatedPath, false);
+        }
+
+        return updatedPath;
     }
 
     @Override
@@ -292,6 +298,9 @@ public class StoragePoolVO implements StoragePool {
 
     public void setPath(String path) {
         this.path = path;
+        if (this.poolType == StoragePoolType.SMB) {
+            this.path = UriUtils.getUpdateUri(this.path, true);
+        }
     }
 
     public void setUserInfo(String userInfo) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
index 21cefb7..9912842 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
@@ -70,8 +70,8 @@ public class PrimaryDataStoreHelper {
         dataStoreVO = new StoragePoolVO();
         dataStoreVO.setStorageProviderName(params.getProviderName());
         dataStoreVO.setHostAddress(params.getHost());
-        dataStoreVO.setPath(params.getPath());
         dataStoreVO.setPoolType(params.getType());
+        dataStoreVO.setPath(params.getPath());
         dataStoreVO.setPort(params.getPort());
         dataStoreVO.setName(params.getName());
         dataStoreVO.setUuid(params.getUuid());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
index c336a38..c2421ef 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
@@ -61,7 +61,7 @@ namespace HypervResource
             get
             {
                 string uncPath = null;
-                if (uri != null && (uri.Scheme.Equals("cifs") || uri.Scheme.Equals("networkfilesystem")))
+                if (uri != null && (uri.Scheme.Equals("cifs") || uri.Scheme.Equals("networkfilesystem") || uri.Scheme.Equals("smb")))
                 {
                     uncPath = @"\\" + uri.Host + uri.LocalPath;
                 }
@@ -584,7 +584,11 @@ namespace HypervResource
         /// <summary>
         /// 
         /// </summary>
-        OCFS2
+        OCFS2,
+        /// <summary>
+        /// for hyper-v
+        /// </summary>
+        SMB
     }
 
     public enum StorageResourceType

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
index ebb3bce..718ef05 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
@@ -916,7 +916,8 @@ namespace HypervResource
                     GetCapacityForLocalPath(localPath, out capacityBytes, out availableBytes);
                     hostPath = localPath;
                 }
-                else if (poolType == StoragePoolType.NetworkFilesystem)
+                else if (poolType == StoragePoolType.NetworkFilesystem ||
+                    poolType == StoragePoolType.SMB)
                 {
                     NFSTO share = new NFSTO();
                     String uriStr = "cifs://" + (string)cmd.pool.host + (string)cmd.pool.path;
@@ -972,7 +973,8 @@ namespace HypervResource
             }
 
             if (poolType != StoragePoolType.Filesystem &&
-                poolType != StoragePoolType.NetworkFilesystem)
+                poolType != StoragePoolType.NetworkFilesystem &&
+                poolType != StoragePoolType.SMB)
             {
                 details = "Request to create / modify unsupported pool type: " + (poolTypeStr == null ? "NULL" : poolTypeStr) + "in cmd " + JsonConvert.SerializeObject(cmd);
                 logger.Error(details);
@@ -1815,7 +1817,7 @@ namespace HypervResource
                         used = capacity - available;
                         result = true;
                     }
-                    else if (poolType == StoragePoolType.NetworkFilesystem)
+                    else if (poolType == StoragePoolType.NetworkFilesystem || poolType == StoragePoolType.SMB)
                     {
                         string sharePath = config.getPrimaryStorage((string)cmd.id);
                         if (sharePath != null)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
index 7da36b0..37861b4 100644
--- a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
+++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
@@ -203,12 +203,11 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
             if (port == -1) {
                 port = 445;
             }
-            parameters.setType(StoragePoolType.NetworkFilesystem);
+
+            parameters.setType(StoragePoolType.SMB);
             parameters.setHost(storageHost);
             parameters.setPort(port);
             parameters.setPath(hostPath);
-            parameters.setUserInfo(uri.getQuery());
-
         } else if (scheme.equalsIgnoreCase("file")) {
             if (port == -1) {
                 port = 0;
@@ -347,10 +346,11 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
 
     protected boolean createStoragePool(long hostId, StoragePool pool) {
         s_logger.debug("creating pool " + pool.getName() + " on  host " + hostId);
+
         if (pool.getPoolType() != StoragePoolType.NetworkFilesystem && pool.getPoolType() != StoragePoolType.Filesystem &&
             pool.getPoolType() != StoragePoolType.IscsiLUN && pool.getPoolType() != StoragePoolType.Iscsi && pool.getPoolType() != StoragePoolType.VMFS &&
             pool.getPoolType() != StoragePoolType.SharedMountPoint && pool.getPoolType() != StoragePoolType.PreSetup && pool.getPoolType() != StoragePoolType.OCFS2 &&
-            pool.getPoolType() != StoragePoolType.RBD && pool.getPoolType() != StoragePoolType.CLVM) {
+            pool.getPoolType() != StoragePoolType.RBD && pool.getPoolType() != StoragePoolType.CLVM && pool.getPoolType() != StoragePoolType.SMB) {
             s_logger.warn(" Doesn't support storage pool type " + pool.getPoolType());
             return false;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a24263fe/utils/src/com/cloud/utils/UriUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/UriUtils.java b/utils/src/com/cloud/utils/UriUtils.java
index 1d5a513..2e771ae 100644
--- a/utils/src/com/cloud/utils/UriUtils.java
+++ b/utils/src/com/cloud/utils/UriUtils.java
@@ -26,7 +26,10 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.ListIterator;
+import java.util.StringTokenizer;
 
 import javax.net.ssl.HttpsURLConnection;
 
@@ -37,10 +40,14 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.util.URIUtil;
 import org.apache.http.NameValuePair;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.client.utils.URLEncodedUtils;
 import org.apache.log4j.Logger;
 
+import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 public class UriUtils {
@@ -138,6 +145,59 @@ public class UriUtils {
         return (foundUser && foundPswd);
     }
 
+    public static String getUpdateUri(String url, boolean encrypt) {
+        String updatedPath = null;
+        try {
+            String query = URIUtil.getQuery(url);
+            URIBuilder builder = new URIBuilder(url);
+            builder.removeQuery();
+
+            String updatedQuery = new String();
+            List<NameValuePair> queryParams = getUserDetails(query);
+            ListIterator<NameValuePair> iterator = queryParams.listIterator();
+            while (iterator.hasNext()) {
+                NameValuePair param = iterator.next();
+                String value = null;
+                if ("password".equalsIgnoreCase(param.getName()) &&
+                        param.getValue() != null) {
+                    value = encrypt ? DBEncryptionUtil.encrypt(param.getValue()) : DBEncryptionUtil.decrypt(param.getValue());
+                } else {
+                    value = param.getValue();
+                }
+
+                if (updatedQuery.isEmpty()) {
+                    updatedQuery += (param.getName() + "=" + value);
+                } else {
+                    updatedQuery += ("&" + param.getName() + "=" + value);
+                }
+            }
+
+            String schemeAndHost = new String();
+            URI newUri = builder.build();
+            if (newUri.getScheme() != null) {
+                schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();
+            }
+
+            updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery;
+        } catch (URISyntaxException e) {
+            throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage());
+        }
+
+        return updatedPath;
+    }
+
+    private static List<NameValuePair> getUserDetails(String query) {
+        List<NameValuePair> details = new ArrayList<NameValuePair>();
+        StringTokenizer allParams = new StringTokenizer(query, "&");
+        while (allParams.hasMoreTokens()) {
+            String param = allParams.nextToken();
+            details.add(new BasicNameValuePair(param.substring(0, param.indexOf("=")),
+                    param.substring(param.indexOf("=") + 1)));
+        }
+
+        return details;
+    }
+
     // Get the size of a file from URL response header.
     public static Long getRemoteSize(String url) {
         Long remoteSize = (long)0;


[42/50] [abbrv] Revert "CLOUDSTACK-6003 fixing plus refactoring dispatcher" as it breaks API dispatching for commands having Map as a parameter type

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/DispatchChainFactory.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/DispatchChainFactory.java b/server/src/com/cloud/api/dispatch/DispatchChainFactory.java
deleted file mode 100644
index f3c6973..0000000
--- a/server/src/com/cloud/api/dispatch/DispatchChainFactory.java
+++ /dev/null
@@ -1,68 +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.dispatch;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-
-import com.cloud.user.AccountManager;
-
-public class DispatchChainFactory {
-
-    @Inject
-    protected AccountManager _accountMgr = null;
-
-    @Inject
-    protected ParamGenericValidationWorker paramGenericValidationWorker = null;
-
-    @Inject
-    protected ParamProcessWorker paramProcessWorker = null;
-
-    @Inject
-    protected ParamSemanticValidationWorker paramSemanticValidationWorker = null;
-
-    @Inject
-    protected CommandCreationWorker commandCreationWorker = null;
-
-    protected DispatchChain standardDispatchChain = null;
-
-    protected DispatchChain asyncCreationDispatchChain = null;
-
-    @PostConstruct
-    public void setup() {
-        standardDispatchChain = new DispatchChain().
-                add(paramGenericValidationWorker).
-                add(paramProcessWorker).
-                add(paramSemanticValidationWorker);
-
-        asyncCreationDispatchChain = new DispatchChain().
-                add(paramGenericValidationWorker).
-                add(paramProcessWorker).
-                add(paramSemanticValidationWorker).
-                add(commandCreationWorker);
-
-    }
-
-    public DispatchChain getStandardDispatchChain() {
-        return standardDispatchChain;
-    }
-
-    public DispatchChain getAsyncCreationDispatchChain() {
-        return asyncCreationDispatchChain;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/DispatchWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/DispatchWorker.java b/server/src/com/cloud/api/dispatch/DispatchWorker.java
deleted file mode 100644
index 5f2b592..0000000
--- a/server/src/com/cloud/api/dispatch/DispatchWorker.java
+++ /dev/null
@@ -1,34 +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.dispatch;
-
-import java.util.Map;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.ServerApiException;
-
-public interface DispatchWorker {
-
-    /**
-    *
-    * @return false to stop the chain of responsibility, true
-    * to continue the chain with the next worker
-    */
-    public boolean handle(BaseCmd cmd, Map<String, Object> params)
-            throws ServerApiException;
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/ParamGenericValidationWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/ParamGenericValidationWorker.java b/server/src/com/cloud/api/dispatch/ParamGenericValidationWorker.java
deleted file mode 100644
index edc1510..0000000
--- a/server/src/com/cloud/api/dispatch/ParamGenericValidationWorker.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.dispatch;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Parameter;
-
-/**
- * This worker validates parameters in a generic way, by using annotated
- * restrictions without involving the {@Link BaseCmd}. This worker doesn't
- * know or care about the meaning of the parameters and that's why we can
- * have it out of the {@Link BaseCmd}
- *
- * @author afornie
- */
-public class ParamGenericValidationWorker implements DispatchWorker {
-
-    protected static Logger s_logger = Logger.getLogger(ParamGenericValidationWorker.class.getName());
-
-    protected static List<String> defaultParamNames = new ArrayList<String>();
-
-    static {
-        defaultParamNames.add(ApiConstants.CTX_START_EVENT_ID);
-        defaultParamNames.add(ApiConstants.COMMAND);
-        defaultParamNames.add(ApiConstants.USERNAME);
-        defaultParamNames.add(ApiConstants.USER_ID);
-        defaultParamNames.add(ApiConstants.PASSWORD);
-        defaultParamNames.add(ApiConstants.DOMAIN);
-        defaultParamNames.add(ApiConstants.DOMAIN_ID);
-        defaultParamNames.add(ApiConstants.DOMAIN__ID);
-        defaultParamNames.add(ApiConstants.SESSIONKEY);
-        defaultParamNames.add(ApiConstants.RESPONSE);
-        defaultParamNames.add(ApiConstants.PAGE);
-        defaultParamNames.add(ApiConstants.PAGE_SIZE);
-        defaultParamNames.add(ApiConstants.HTTPMETHOD);
-        defaultParamNames.add("_");
-    }
-
-    protected static final String ERROR_MSG_PREFIX = "Unknown parameters :";
-
-    @Override
-    public boolean handle(final BaseCmd cmd, final Map<String, Object> params) {
-        final List<String> expectedParamNames = getParamNamesForCommand(cmd);
-
-        final StringBuilder errorMsg = new StringBuilder(ERROR_MSG_PREFIX);
-        boolean foundUnknownParam = false;
-        for (final String paramName : params.keySet()) {
-            if (!expectedParamNames.contains(paramName)) {
-                errorMsg.append(" ").append(paramName);
-                foundUnknownParam= true;
-            }
-        }
-
-        if (foundUnknownParam) {
-            s_logger.warn(String.format("Received unkown parameters for command %s. %s", cmd.getCommandName(), errorMsg));
-        }
-
-        return true;
-    }
-
-    protected List<String> getParamNamesForCommand(final BaseCmd cmd) {
-        final List<String> paramNames = new ArrayList<String>();
-        // The expected param names are all the specific for the current command class ...
-        for (final Field field : cmd.getParamFields()) {
-            final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
-            paramNames.add(parameterAnnotation.name());
-        }
-        // ... plus the default ones
-        paramNames.addAll(defaultParamNames);
-        return paramNames;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
deleted file mode 100644
index 6c058c3..0000000
--- a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
+++ /dev/null
@@ -1,429 +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.dispatch;
-
-import static org.apache.commons.lang.StringUtils.isNotBlank;
-
-import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-
-import javax.inject.Inject;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.acl.ControlledEntity;
-import org.apache.cloudstack.acl.InfrastructureEntity;
-import org.apache.cloudstack.acl.SecurityChecker.AccessType;
-import org.apache.cloudstack.api.ACL;
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.EntityReference;
-import org.apache.cloudstack.api.InternalIdentity;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.BaseCmd.CommandType;
-import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
-import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
-import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
-import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
-import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.utils.DateUtil;
-import com.cloud.utils.db.EntityManager;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public class ParamProcessWorker implements DispatchWorker {
-
-    private static final Logger s_logger = Logger.getLogger(ParamProcessWorker.class.getName());
-
-    @Inject
-    protected AccountManager _accountMgr = null;
-
-    @Inject
-    protected EntityManager _entityMgr = null;
-
-    @Override
-    public boolean handle(final BaseCmd cmd, final Map<String, Object> params) {
-        processParameters(cmd, params);
-        return true;
-    }
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    public void processParameters(final BaseCmd cmd, final Map<String, Object> params) {
-        final Map<Object, AccessType> entitiesToAccess = new HashMap<Object, AccessType>();
-
-        final List<Field> cmdFields = cmd.getParamFields();
-
-        for (final Field field : cmdFields) {
-            final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
-            final Object paramObj = params.get(parameterAnnotation.name());
-            if (paramObj == null) {
-                if (parameterAnnotation.required()) {
-                    throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
-                        cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
-                        " due to missing parameter " + parameterAnnotation.name());
-                }
-                continue;
-            }
-
-            // marshall the parameter into the correct type and set the field value
-            try {
-                setFieldValue(field, cmd, paramObj, parameterAnnotation);
-            } catch (final IllegalArgumentException argEx) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " +
-                            parameterAnnotation.name());
-                }
-                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
-                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
-                    parameterAnnotation.name());
-            } catch (final ParseException parseEx) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
-                }
-                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
-                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
-            } catch (final InvalidParameterValueException invEx) {
-                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
-                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
-            } catch (final CloudRuntimeException cloudEx) {
-                s_logger.error("CloudRuntimeException", cloudEx);
-                // FIXME: Better error message? This only happens if the API command is not executable, which typically
-                //means
-                // there was
-                // and IllegalAccessException setting one of the parameters.
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
-                    cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
-            }
-
-            //check access on the resource this field points to
-            try {
-                final ACL checkAccess = field.getAnnotation(ACL.class);
-                final CommandType fieldType = parameterAnnotation.type();
-
-                if (checkAccess != null) {
-                    // Verify that caller can perform actions in behalf of vm owner
-                    //acumulate all Controlled Entities together.
-
-                    //parse the array of resource types and in case of map check access on key or value or both as specified in @acl
-                    //implement external dao for classes that need findByName
-                    //for maps, specify access to be checkd on key or value.
-
-                    // find the controlled entity DBid by uuid
-                    if (parameterAnnotation.entityType() != null) {
-                        final Class<?>[] entityList = parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class).value();
-
-                        for (final Class entity : entityList) {
-                            // Check if the parameter type is a single
-                            // Id or list of id's/name's
-                            switch (fieldType) {
-                                case LIST:
-                                    final CommandType listType = parameterAnnotation.collectionType();
-                                    switch (listType) {
-                                        case LONG:
-                                        case UUID:
-                                            final List<Long> listParam = (List<Long>)field.get(cmd);
-                                            for (final Long entityId : listParam) {
-                                                final Object entityObj = _entityMgr.findById(entity, entityId);
-                                                entitiesToAccess.put(entityObj, checkAccess.accessType());
-                                            }
-                                            break;
-                                        /*
-                                         * case STRING: List<String> listParam =
-                                         * new ArrayList<String>(); listParam =
-                                         * (List)field.get(cmd); for(String
-                                         * entityName: listParam){
-                                         * ControlledEntity entityObj =
-                                         * (ControlledEntity
-                                         * )daoClassInstance(entityId);
-                                         * entitiesToAccess.add(entityObj); }
-                                         * break;
-                                         */
-                                        default:
-                                            break;
-                                    }
-                                    break;
-                                case LONG:
-                                case UUID:
-                                    final Object entityObj = _entityMgr.findById(entity, (Long)field.get(cmd));
-                                    entitiesToAccess.put(entityObj, checkAccess.accessType());
-                                    break;
-                                default:
-                                    break;
-                            }
-
-                            if (ControlledEntity.class.isAssignableFrom(entity)) {
-                                if (s_logger.isDebugEnabled()) {
-                                    s_logger.debug("ControlledEntity name is:" + entity.getName());
-                                }
-                            }
-
-                            if (InfrastructureEntity.class.isAssignableFrom(entity)) {
-                                if (s_logger.isDebugEnabled()) {
-                                    s_logger.debug("InfrastructureEntity name is:" + entity.getName());
-                                }
-                            }
-                        }
-
-                    }
-
-                }
-
-            } catch (final IllegalArgumentException e) {
-                s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
-                throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
-                    " is not accessible]");
-            } catch (final IllegalAccessException e) {
-                s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
-                throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
-                    " is not accessible]");
-            }
-
-        }
-
-        doAccessChecks(cmd, entitiesToAccess);
-    }
-
-
-    private void doAccessChecks(final BaseCmd cmd, final Map<Object, AccessType> entitiesToAccess) {
-        final Account caller = CallContext.current().getCallingAccount();
-        final Account owner = _accountMgr.getActiveAccountById(cmd.getEntityOwnerId());
-
-        if (cmd instanceof BaseAsyncCreateCmd) {
-            //check that caller can access the owner account.
-            _accountMgr.checkAccess(caller, null, true, owner);
-        }
-
-        if (!entitiesToAccess.isEmpty()) {
-            //check that caller can access the owner account.
-            _accountMgr.checkAccess(caller, null, true, owner);
-            for (final Object entity : entitiesToAccess.keySet()) {
-                if (entity instanceof ControlledEntity) {
-                    _accountMgr.checkAccess(caller, entitiesToAccess.get(entity), true, (ControlledEntity)entity);
-                } else if (entity instanceof InfrastructureEntity) {
-                    //FIXME: Move this code in adapter, remove code from Account manager
-                }
-            }
-        }
-    }
-
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation) throws IllegalArgumentException, ParseException {
-        try {
-            field.setAccessible(true);
-            final CommandType fieldType = annotation.type();
-            switch (fieldType) {
-                case BOOLEAN:
-                    field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
-                    break;
-                case DATE:
-                    // This piece of code is for maintaining backward compatibility
-                    // and support both the date formats(Bug 9724)
-                    // Do the date messaging for ListEventsCmd only
-                    if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
-                        cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd) {
-                        final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
-                        if (isObjInNewDateFormat) {
-                            final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
-                            synchronized (newFormat) {
-                                field.set(cmdObj, newFormat.parse(paramObj.toString()));
-                            }
-                        } else {
-                            final DateFormat format = BaseCmd.INPUT_FORMAT;
-                            synchronized (format) {
-                                Date date = format.parse(paramObj.toString());
-                                if (field.getName().equals("startDate")) {
-                                    date = messageDate(date, 0, 0, 0);
-                                } else if (field.getName().equals("endDate")) {
-                                    date = messageDate(date, 23, 59, 59);
-                                }
-                                field.set(cmdObj, date);
-                            }
-                        }
-                    } else {
-                        final DateFormat format = BaseCmd.INPUT_FORMAT;
-                        format.setLenient(false);
-                        synchronized (format) {
-                            field.set(cmdObj, format.parse(paramObj.toString()));
-                        }
-                    }
-                    break;
-                case FLOAT:
-                    // Assuming that the parameters have been checked for required before now,
-                    // we ignore blank or null values and defer to the command to set a default
-                    // value for optional parameters ...
-                    if (paramObj != null && isNotBlank(paramObj.toString())) {
-                        field.set(cmdObj, Float.valueOf(paramObj.toString()));
-                    }
-                    break;
-                case INTEGER:
-                    // Assuming that the parameters have been checked for required before now,
-                    // we ignore blank or null values and defer to the command to set a default
-                    // value for optional parameters ...
-                    if (paramObj != null && isNotBlank(paramObj.toString())) {
-                        field.set(cmdObj, Integer.valueOf(paramObj.toString()));
-                    }
-                    break;
-                case LIST:
-                    final List listParam = new ArrayList();
-                    final StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
-                    while (st.hasMoreTokens()) {
-                        final String token = st.nextToken();
-                        final CommandType listType = annotation.collectionType();
-                        switch (listType) {
-                            case INTEGER:
-                                listParam.add(Integer.valueOf(token));
-                                break;
-                            case UUID:
-                                if (token.isEmpty())
-                                    break;
-                                final Long internalId = translateUuidToInternalId(token, annotation);
-                                listParam.add(internalId);
-                                break;
-                            case LONG: {
-                                listParam.add(Long.valueOf(token));
-                            }
-                                break;
-                            case SHORT:
-                                listParam.add(Short.valueOf(token));
-                            case STRING:
-                                listParam.add(token);
-                                break;
-                        }
-                    }
-                    field.set(cmdObj, listParam);
-                    break;
-                case UUID:
-                    if (paramObj.toString().isEmpty())
-                        break;
-                    final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
-                    field.set(cmdObj, internalId);
-                    break;
-                case LONG:
-                    field.set(cmdObj, Long.valueOf(paramObj.toString()));
-                    break;
-                case SHORT:
-                    field.set(cmdObj, Short.valueOf(paramObj.toString()));
-                    break;
-                case STRING:
-                    if ((paramObj != null) && paramObj.toString().length() > annotation.length()) {
-                        s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
-                        throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
-                    }
-                    field.set(cmdObj, paramObj.toString());
-                    break;
-                case TZDATE:
-                    field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
-                    break;
-                case MAP:
-                default:
-                    field.set(cmdObj, paramObj);
-                    break;
-            }
-        } catch (final IllegalAccessException ex) {
-            s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible.");
-            throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() +
-                " is not accessible]");
-        }
-    }
-
-    private boolean isObjInNewDateFormat(final String string) {
-        final Matcher matcher = BaseCmd.newInputDateFormat.matcher(string);
-        return matcher.matches();
-    }
-
-    private Date messageDate(final Date date, final int hourOfDay, final int minute, final int second) {
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(date);
-        cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
-        cal.set(Calendar.MINUTE, minute);
-        cal.set(Calendar.SECOND, second);
-        return cal.getTime();
-    }
-
-    private Long translateUuidToInternalId(final String uuid, final Parameter annotation) {
-        if (uuid.equals("-1")) {
-            // FIXME: This is to handle a lot of hardcoded special cases where -1 is sent
-            // APITODO: Find and get rid of all hardcoded params in API Cmds and service layer
-            return -1L;
-        }
-        Long internalId = null;
-        // If annotation's empty, the cmd existed before 3.x try conversion to long
-        final boolean isPre3x = annotation.since().isEmpty();
-        // Match against Java's UUID regex to check if input is uuid string
-        final boolean isUuid = uuid.matches("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
-        // Enforce that it's uuid for newly added apis from version 3.x
-        if (!isPre3x && !isUuid)
-            return null;
-        // Allow both uuid and internal id for pre3x apis
-        if (isPre3x && !isUuid) {
-            try {
-                internalId = Long.parseLong(uuid);
-            } catch (final NumberFormatException e) {
-                internalId = null;
-            }
-            if (internalId != null)
-                return internalId;
-        }
-        // There may be multiple entities defined on the @EntityReference of a Response.class
-        // UUID CommandType would expect only one entityType, so use the first entityType
-        final Class<?>[] entities = annotation.entityType()[0].getAnnotation(EntityReference.class).value();
-        // Go through each entity which is an interface to a VO class and get a VO object
-        // Try to getId() for the object using reflection, break on first non-null value
-        for (final Class<?> entity : entities) {
-            // For backward compatibility, we search within removed entities and let service layer deal
-            // with removed ones, return empty response or error
-            final Object objVO = _entityMgr.findByUuidIncludingRemoved(entity, uuid);
-            if (objVO == null) {
-                continue;
-            }
-            // Invoke the getId method, get the internal long ID
-            // If that fails hide exceptions as the uuid may not exist
-            try {
-                internalId = ((InternalIdentity)objVO).getId();
-            } catch (final IllegalArgumentException e) {
-            } catch (final NullPointerException e) {
-            }
-            // Return on first non-null Id for the uuid entity
-            if (internalId != null)
-                break;
-        }
-        if (internalId == null) {
-            if (s_logger.isDebugEnabled())
-                s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
-            throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
-                " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
-        }
-        return internalId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/782c5306/server/src/com/cloud/api/dispatch/ParamSemanticValidationWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/ParamSemanticValidationWorker.java b/server/src/com/cloud/api/dispatch/ParamSemanticValidationWorker.java
deleted file mode 100644
index 4733dcc..0000000
--- a/server/src/com/cloud/api/dispatch/ParamSemanticValidationWorker.java
+++ /dev/null
@@ -1,40 +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.dispatch;
-
-import java.util.Map;
-
-import org.apache.cloudstack.api.BaseCmd;
-
-
-/**
- * This worker validates parameters in a semantic way, that is of
- * course specific for each {@link BaseCmd}, so actually it delegates
- * the validation on the {@link BaseCmd} itself
- *
- * @author afornie
- */
-public class ParamSemanticValidationWorker implements DispatchWorker {
-
-    @Override
-    public boolean handle(final BaseCmd cmd, final Map<String, Object> params) {
-        cmd.validateSpecificParameters(params);
-        return true;
-    }
-
-}


[03/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
deleted file mode 100755
index ee50647..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageDiscoverer.java
+++ /dev/null
@@ -1,312 +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.storage.resource;
-
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URI;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status.Event;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.resource.Discoverer;
-import com.cloud.resource.DiscovererBase;
-import com.cloud.resource.ServerResource;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VMTemplateZoneVO;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplateZoneDao;
-import com.cloud.storage.resource.DummySecondaryStorageResource;
-import com.cloud.utils.component.ComponentContext;
-import com.cloud.utils.net.NfsUtils;
-import com.cloud.utils.script.Script;
-
-/**
- * SecondaryStorageDiscoverer is used to discover secondary
- * storage servers and make sure everything it can do is
- * correct.
- */
-@Local(value = Discoverer.class)
-public class SecondaryStorageDiscoverer extends DiscovererBase implements Discoverer {
-    private static final Logger s_logger = Logger.getLogger(SecondaryStorageDiscoverer.class);
-
-    long _timeout = 2 * 60 * 1000; // 2 minutes
-    String _mountParent;
-    boolean _useServiceVM = false;
-
-    Random _random = new Random(System.currentTimeMillis());
-    @Inject
-    protected VMTemplateDao _tmpltDao = null;
-    @Inject
-    protected VMTemplateZoneDao _vmTemplateZoneDao = null;
-    @Inject
-    protected VMTemplateDao _vmTemplateDao = null;
-    @Inject
-    protected AgentManager _agentMgr = null;
-
-    protected SecondaryStorageDiscoverer() {
-    }
-
-    @Override
-    public Map<? extends ServerResource, Map<String, String>>
-        find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) {
-        if (!uri.getScheme().equalsIgnoreCase("nfs") && !uri.getScheme().equalsIgnoreCase("cifs") && !uri.getScheme().equalsIgnoreCase("file") &&
-            !uri.getScheme().equalsIgnoreCase("iso") && !uri.getScheme().equalsIgnoreCase("dummy")) {
-            s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString());
-            return null;
-        }
-
-        if (uri.getScheme().equalsIgnoreCase("nfs") || uri.getScheme().equalsIgnoreCase("cifs") || uri.getScheme().equalsIgnoreCase("iso")) {
-            return createNfsSecondaryStorageResource(dcId, podId, uri);
-        } else if (uri.getScheme().equalsIgnoreCase("file")) {
-            return createLocalSecondaryStorageResource(dcId, podId, uri);
-        } else if (uri.getScheme().equalsIgnoreCase("dummy")) {
-            return createDummySecondaryStorageResource(dcId, podId, uri);
-        } else {
-            return null;
-        }
-    }
-
-    protected Map<? extends ServerResource, Map<String, String>> createNfsSecondaryStorageResource(long dcId, Long podId, URI uri) {
-
-        if (_useServiceVM) {
-            return createDummySecondaryStorageResource(dcId, podId, uri);
-        }
-        String mountStr = NfsUtils.uri2Mount(uri);
-
-        Script script = new Script(true, "mount", _timeout, s_logger);
-        String mntPoint = null;
-        File file = null;
-        do {
-            mntPoint = _mountParent + File.separator + Integer.toHexString(_random.nextInt(Integer.MAX_VALUE));
-            file = new File(mntPoint);
-        } while (file.exists());
-
-        if (!file.mkdirs()) {
-            s_logger.warn("Unable to make directory: " + mntPoint);
-            return null;
-        }
-
-        script.add(mountStr, mntPoint);
-        String result = script.execute();
-        if (result != null && !result.contains("already mounted")) {
-            s_logger.warn("Unable to mount " + uri.toString() + " due to " + result);
-            file.delete();
-            return null;
-        }
-
-        script = new Script(true, "umount", 0, s_logger);
-        script.add(mntPoint);
-        script.execute();
-
-        file.delete();
-
-        Map<NfsSecondaryStorageResource, Map<String, String>> srs = new HashMap<NfsSecondaryStorageResource, Map<String, String>>();
-
-        NfsSecondaryStorageResource storage;
-        if (_configDao.isPremium()) {
-            Class<?> impl;
-            String name = "com.cloud.storage.resource.PremiumSecondaryStorageResource";
-            try {
-                impl = Class.forName(name);
-                final Constructor<?> constructor = impl.getDeclaredConstructor();
-                constructor.setAccessible(true);
-                storage = (NfsSecondaryStorageResource)constructor.newInstance();
-            } catch (final ClassNotFoundException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to ClassNotFoundException");
-                return null;
-            } catch (final SecurityException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to SecurityException");
-                return null;
-            } catch (final NoSuchMethodException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to NoSuchMethodException");
-                return null;
-            } catch (final IllegalArgumentException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalArgumentException");
-                return null;
-            } catch (final InstantiationException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InstantiationException");
-                return null;
-            } catch (final IllegalAccessException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalAccessException");
-                return null;
-            } catch (final InvocationTargetException e) {
-                s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InvocationTargetException");
-                return null;
-            }
-        } else {
-            storage = new NfsSecondaryStorageResource();
-        }
-
-        Map<String, String> details = new HashMap<String, String>();
-        details.put("mount.path", mountStr);
-        details.put("orig.url", uri.toString());
-        details.put("mount.parent", _mountParent);
-
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.putAll(details);
-        params.put("zone", Long.toString(dcId));
-        if (podId != null) {
-            params.put("pod", podId.toString());
-        }
-        params.put("guid", uri.toString());
-        params.put("secondary.storage.vm", "false");
-        params.put("max.template.iso.size", _configDao.getValue("max.template.iso.size"));
-
-        try {
-            storage.configure("Storage", params);
-        } catch (ConfigurationException e) {
-            s_logger.warn("Unable to configure the storage ", e);
-            return null;
-        }
-        srs.put(storage, details);
-
-        return srs;
-    }
-
-    protected Map<? extends ServerResource, Map<String, String>> createLocalSecondaryStorageResource(long dcId, Long podId, URI uri) {
-        Map<LocalSecondaryStorageResource, Map<String, String>> srs = new HashMap<LocalSecondaryStorageResource, Map<String, String>>();
-
-        LocalSecondaryStorageResource storage = new LocalSecondaryStorageResource();
-        storage = ComponentContext.inject(storage);
-
-        Map<String, String> details = new HashMap<String, String>();
-
-        File file = new File(uri);
-        details.put("mount.path", file.getAbsolutePath());
-        details.put("orig.url", uri.toString());
-
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.putAll(details);
-        params.put("zone", Long.toString(dcId));
-        if (podId != null) {
-            params.put("pod", podId.toString());
-        }
-        params.put("guid", uri.toString());
-
-        try {
-            storage.configure("Storage", params);
-        } catch (ConfigurationException e) {
-            s_logger.warn("Unable to configure the storage ", e);
-            return null;
-        }
-        srs.put(storage, details);
-
-        return srs;
-    }
-
-    protected Map<ServerResource, Map<String, String>> createDummySecondaryStorageResource(long dcId, Long podId, URI uri) {
-        Map<ServerResource, Map<String, String>> srs = new HashMap<ServerResource, Map<String, String>>();
-
-        DummySecondaryStorageResource storage = new DummySecondaryStorageResource(_useServiceVM);
-        storage = ComponentContext.inject(storage);
-
-        Map<String, String> details = new HashMap<String, String>();
-
-        details.put("mount.path", uri.toString());
-        details.put("orig.url", uri.toString());
-
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.putAll(details);
-        params.put("zone", Long.toString(dcId));
-        if (podId != null) {
-            params.put("pod", podId.toString());
-        }
-        params.put("guid", uri.toString());
-
-        try {
-            storage.configure("Storage", params);
-        } catch (ConfigurationException e) {
-            s_logger.warn("Unable to configure the storage ", e);
-            return null;
-        }
-        srs.put(storage, details);
-
-        return srs;
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        _mountParent = _params.get("mount.parent");
-        if (_mountParent == null) {
-            _mountParent = "/mnt";
-        }
-
-        String useServiceVM = _params.get("secondary.storage.vm");
-        if ("true".equalsIgnoreCase(useServiceVM)) {
-            _useServiceVM = true;
-        }
-        return true;
-    }
-
-    @Override
-    public boolean matchHypervisor(String hypervisor) {
-        if (hypervisor.equals("SecondaryStorage")) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    @Override
-    public Hypervisor.HypervisorType getHypervisorType() {
-        return Hypervisor.HypervisorType.None;
-    }
-
-    @Override
-    public void postDiscovery(List<HostVO> hosts, long msId) {
-        if (_useServiceVM) {
-            for (HostVO h : hosts) {
-                _agentMgr.agentStatusTransitTo(h, Event.AgentDisconnected, msId);
-            }
-        }
-        for (HostVO h : hosts) {
-            associateTemplatesToZone(h.getId(), h.getDataCenterId());
-        }
-
-    }
-
-    private void associateTemplatesToZone(long hostId, long dcId) {
-        VMTemplateZoneVO tmpltZone;
-
-        List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
-        for (VMTemplateVO vt : allTemplates) {
-            if (vt.isCrossZones()) {
-                tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
-                if (tmpltZone == null) {
-                    VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
-                    _vmTemplateZoneDao.persist(vmTemplateZone);
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
deleted file mode 100755
index 93fd8ea..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResource.java
+++ /dev/null
@@ -1,29 +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.storage.resource;
-
-import com.cloud.resource.ServerResource;
-
-/**
- *
- * SecondaryStorageServerResource is a generic container to execute commands sent
- */
-public interface SecondaryStorageResource extends ServerResource {
-
-    public String getRootDir(String cmd);
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
deleted file mode 100644
index 14ebc71..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/SecondaryStorageResourceHandler.java
+++ /dev/null
@@ -1,24 +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.storage.resource;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-
-public interface SecondaryStorageResourceHandler {
-    Answer executeRequest(Command cmd);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManager.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManager.java b/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManager.java
deleted file mode 100644
index d0abe2c..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManager.java
+++ /dev/null
@@ -1,108 +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.storage.template;
-
-import java.util.Map;
-
-import org.apache.cloudstack.storage.command.DownloadCommand;
-import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
-import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
-
-import com.cloud.agent.api.storage.DownloadAnswer;
-import com.cloud.agent.api.storage.Proxy;
-import com.cloud.agent.api.to.S3TO;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.template.TemplateDownloader;
-import com.cloud.storage.template.TemplateProp;
-import com.cloud.utils.component.Manager;
-
-public interface DownloadManager extends Manager {
-
-    /**
-     * Initiate download of a public template
-     * @param id unique id.
-     * @param url  the url from where to download from
-     * @param hvm  whether the template is a hardware virtual machine
-     * @param accountId the accountId of the iso owner (null if public iso)
-     * @param descr    description of the template
-     * @param user username used for authentication to the server
-     * @param password password used for authentication to the server
-     * @param maxDownloadSizeInBytes (optional) max download size for the template, in bytes.
-     * @param resourceType signifying the type of resource like template, volume etc.
-     * @return job-id that can be used to interrogate the status of the download.
-     */
-    public String downloadPublicTemplate(long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-        String installPathPrefix, String templatePath, String userName, String passwd, long maxDownloadSizeInBytes, Proxy proxy, ResourceType resourceType);
-
-    public String downloadS3Template(S3TO s3, long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-        String installPathPrefix, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType);
-
-    /**
-     * Get the status of a download job
-     * @param jobId job Id
-     * @return status of the download job
-     */
-    public TemplateDownloader.Status getDownloadStatus(String jobId);
-
-    /**
-     * Get the status of a download job
-     * @param jobId job Id
-     * @return status of the download job
-     */
-    public VMTemplateHostVO.Status getDownloadStatus2(String jobId);
-
-    /**
-     * Get the download percent of a download job
-     * @param jobId job Id
-     * @return
-     */
-    public int getDownloadPct(String jobId);
-
-    /**
-     * Get the download error if any
-     * @param jobId job Id
-     * @return
-     */
-    public String getDownloadError(String jobId);
-
-    /**
-     * Get the local path for the download
-     * @param jobId job Id
-     * @return
-    public String getDownloadLocalPath(String jobId);
-     */
-
-    /** Handle download commands from the management server
-     * @param cmd cmd from server
-     * @return answer representing status of download.
-     */
-    public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd);
-
-    /**
-    /**
-     * @return list of template info for installed templates
-     */
-    public Map<String, TemplateProp> gatherTemplateInfo(String templateDir);
-
-    /**
-    /**
-     * @return list of volume info for installed volumes
-     */
-    public Map<Long, TemplateProp> gatherVolumeInfo(String volumeDir);
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java b/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
deleted file mode 100755
index d45a6bb..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
+++ /dev/null
@@ -1,1080 +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.storage.template;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.storage.command.DownloadCommand;
-import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
-import org.apache.cloudstack.storage.command.DownloadProgressCommand;
-import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
-import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
-
-import com.cloud.agent.api.storage.DownloadAnswer;
-import com.cloud.agent.api.storage.Proxy;
-import com.cloud.agent.api.to.DataStoreTO;
-import com.cloud.agent.api.to.NfsTO;
-import com.cloud.agent.api.to.S3TO;
-import com.cloud.exception.InternalErrorException;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.StorageLayer;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.template.HttpTemplateDownloader;
-import com.cloud.storage.template.IsoProcessor;
-import com.cloud.storage.template.LocalTemplateDownloader;
-import com.cloud.storage.template.OVAProcessor;
-import com.cloud.storage.template.Processor;
-import com.cloud.storage.template.Processor.FormatInfo;
-import com.cloud.storage.template.QCOW2Processor;
-import com.cloud.storage.template.RawImageProcessor;
-import com.cloud.storage.template.S3TemplateDownloader;
-import com.cloud.storage.template.ScpTemplateDownloader;
-import com.cloud.storage.template.TemplateConstants;
-import com.cloud.storage.template.TemplateDownloader;
-import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
-import com.cloud.storage.template.TemplateDownloader.Status;
-import com.cloud.storage.template.TemplateLocation;
-import com.cloud.storage.template.TemplateProp;
-import com.cloud.storage.template.VhdProcessor;
-import com.cloud.storage.template.VmdkProcessor;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.OutputInterpreter;
-import com.cloud.utils.script.Script;
-
-@Local(value = DownloadManager.class)
-public class DownloadManagerImpl extends ManagerBase implements DownloadManager {
-    private String _name;
-    StorageLayer _storage;
-    Map<String, Processor> _processors;
-
-    public class Completion implements DownloadCompleteCallback {
-        private final String jobId;
-
-        public Completion(String jobId) {
-            this.jobId = jobId;
-        }
-
-        @Override
-        public void downloadComplete(Status status) {
-            setDownloadStatus(jobId, status);
-        }
-    }
-
-    private static class DownloadJob {
-        private final TemplateDownloader td;
-        private final String tmpltName;
-        private final boolean hvm;
-        private final ImageFormat format;
-        private String tmpltPath;
-        private final String description;
-        private String checksum;
-        private final String installPathPrefix;
-        private long templatesize;
-        private long templatePhysicalSize;
-        private final long id;
-        private final ResourceType resourceType;
-
-        public DownloadJob(TemplateDownloader td, String jobId, long id, String tmpltName, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-                String installPathPrefix, ResourceType resourceType) {
-            super();
-            this.td = td;
-            this.tmpltName = tmpltName;
-            this.format = format;
-            this.hvm = hvm;
-            description = descr;
-            checksum = cksum;
-            this.installPathPrefix = installPathPrefix;
-            templatesize = 0;
-            this.id = id;
-            this.resourceType = resourceType;
-        }
-
-        public String getDescription() {
-            return description;
-        }
-
-        public String getChecksum() {
-            return checksum;
-        }
-
-        public TemplateDownloader getTemplateDownloader() {
-            return td;
-        }
-
-        public String getTmpltName() {
-            return tmpltName;
-        }
-
-        public ImageFormat getFormat() {
-            return format;
-        }
-
-        public boolean isHvm() {
-            return hvm;
-        }
-
-        public long getId() {
-            return id;
-        }
-
-        public ResourceType getResourceType() {
-            return resourceType;
-        }
-
-        public void setTmpltPath(String tmpltPath) {
-            this.tmpltPath = tmpltPath;
-        }
-
-        public String getTmpltPath() {
-            return tmpltPath;
-        }
-
-        public String getInstallPathPrefix() {
-            return installPathPrefix;
-        }
-
-        public void cleanup() {
-            if (td != null) {
-                String dnldPath = td.getDownloadLocalPath();
-                if (dnldPath != null) {
-                    File f = new File(dnldPath);
-                    File dir = f.getParentFile();
-                    f.delete();
-                    if (dir != null) {
-                        dir.delete();
-                    }
-                }
-            }
-
-        }
-
-        public void setTemplatesize(long templatesize) {
-            this.templatesize = templatesize;
-        }
-
-        public long getTemplatesize() {
-            return templatesize;
-        }
-
-        public void setTemplatePhysicalSize(long templatePhysicalSize) {
-            this.templatePhysicalSize = templatePhysicalSize;
-        }
-
-        public long getTemplatePhysicalSize() {
-            return templatePhysicalSize;
-        }
-
-        public void setCheckSum(String checksum) {
-            this.checksum = checksum;
-        }
-    }
-
-    public static final Logger s_logger = Logger.getLogger(DownloadManagerImpl.class);
-    private String _templateDir;
-    private String _volumeDir;
-    private String createTmpltScr;
-    private String createVolScr;
-
-    private ExecutorService threadPool;
-
-    private final Map<String, DownloadJob> jobs = new ConcurrentHashMap<String, DownloadJob>();
-    private String listTmpltScr;
-    private String listVolScr;
-    private int installTimeoutPerGig = 180 * 60 * 1000;
-
-    public void setThreadPool(ExecutorService threadPool) {
-        this.threadPool = threadPool;
-    }
-
-    public void setStorageLayer(StorageLayer storage) {
-        _storage = storage;
-    }
-
-    /**
-     * Get notified of change of job status. Executed in context of downloader
-     * thread
-     *
-     * @param jobId
-     *            the id of the job
-     * @param status
-     *            the status of the job
-     */
-    public void setDownloadStatus(String jobId, Status status) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj == null) {
-            s_logger.warn("setDownloadStatus for jobId: " + jobId + ", status=" + status + " no job found");
-            return;
-        }
-        TemplateDownloader td = dj.getTemplateDownloader();
-        s_logger.info("Download Completion for jobId: " + jobId + ", status=" + status);
-        s_logger.info("local: " + td.getDownloadLocalPath() + ", bytes=" + td.getDownloadedBytes() + ", error=" + td.getDownloadError() + ", pct=" +
-                td.getDownloadPercent());
-
-        switch (status) {
-        case ABORTED:
-        case NOT_STARTED:
-        case UNRECOVERABLE_ERROR:
-            // TODO
-            dj.cleanup();
-            break;
-        case UNKNOWN:
-            return;
-        case IN_PROGRESS:
-            s_logger.info("Resuming jobId: " + jobId + ", status=" + status);
-            td.setResume(true);
-            threadPool.execute(td);
-            break;
-        case RECOVERABLE_ERROR:
-            threadPool.execute(td);
-            break;
-        case DOWNLOAD_FINISHED:
-            if (!(td instanceof S3TemplateDownloader)) {
-                // we currently only create template.properties for NFS by
-                // running some post download script
-                td.setDownloadError("Download success, starting install ");
-                String result = postDownload(jobId);
-                if (result != null) {
-                    s_logger.error("Failed post download script: " + result);
-                    td.setStatus(Status.UNRECOVERABLE_ERROR);
-                    td.setDownloadError("Failed post download script: " + result);
-                } else {
-                    td.setStatus(Status.POST_DOWNLOAD_FINISHED);
-                    td.setDownloadError("Install completed successfully at " + new SimpleDateFormat().format(new Date()));
-                }
-            } else {
-                // for s3 and swift, we skip post download step and just set
-                // status to trigger callback.
-                td.setStatus(Status.POST_DOWNLOAD_FINISHED);
-                // set template size for S3
-                S3TemplateDownloader std = (S3TemplateDownloader)td;
-                long size = std.totalBytes;
-                DownloadJob dnld = jobs.get(jobId);
-                dnld.setTemplatesize(size);
-                dnld.setTemplatePhysicalSize(size);
-                dnld.setTmpltPath(std.getDownloadLocalPath()); // update template path to include file name.
-            }
-            dj.cleanup();
-            break;
-        default:
-            break;
-        }
-    }
-
-    private String computeCheckSum(File f) {
-        byte[] buffer = new byte[8192];
-        int read = 0;
-        MessageDigest digest;
-        String checksum = null;
-        InputStream is = null;
-        try {
-            digest = MessageDigest.getInstance("MD5");
-            is = new FileInputStream(f);
-            while ((read = is.read(buffer)) > 0) {
-                digest.update(buffer, 0, read);
-            }
-            byte[] md5sum = digest.digest();
-            BigInteger bigInt = new BigInteger(1, md5sum);
-            checksum = String.format("%032x", bigInt);
-            return checksum;
-        } catch (IOException e) {
-            return null;
-        } catch (NoSuchAlgorithmException e) {
-            return null;
-        } finally {
-            try {
-                if (is != null)
-                    is.close();
-            } catch (IOException e) {
-                return null;
-            }
-        }
-    }
-
-    /**
-     * Post download activity (install and cleanup). Executed in context of
-     * downloader thread
-     *
-     * @throws IOException
-     */
-    private String postDownload(String jobId) {
-        DownloadJob dnld = jobs.get(jobId);
-        TemplateDownloader td = dnld.getTemplateDownloader();
-        String resourcePath = dnld.getInstallPathPrefix(); // path with mount
-        // directory
-        String finalResourcePath = dnld.getTmpltPath(); // template download
-        // path on secondary
-        // storage
-        ResourceType resourceType = dnld.getResourceType();
-
-        File originalTemplate = new File(td.getDownloadLocalPath());
-        String checkSum = computeCheckSum(originalTemplate);
-        if (checkSum == null) {
-            s_logger.warn("Something wrong happened when try to calculate the checksum of downloaded template!");
-        }
-        dnld.setCheckSum(checkSum);
-
-        int imgSizeGigs = (int)Math.ceil(_storage.getSize(td.getDownloadLocalPath()) * 1.0d / (1024 * 1024 * 1024));
-        imgSizeGigs++; // add one just in case
-        long timeout = imgSizeGigs * installTimeoutPerGig;
-        Script scr = null;
-        String script = resourceType == ResourceType.TEMPLATE ? createTmpltScr : createVolScr;
-        scr = new Script(script, timeout, s_logger);
-        scr.add("-s", Integer.toString(imgSizeGigs));
-        scr.add("-S", Long.toString(td.getMaxTemplateSizeInBytes()));
-        if (dnld.getDescription() != null && dnld.getDescription().length() > 1) {
-            scr.add("-d", dnld.getDescription());
-        }
-        if (dnld.isHvm()) {
-            scr.add("-h");
-        }
-
-        // add options common to ISO and template
-        String extension = dnld.getFormat().getFileExtension();
-        String templateName = "";
-        if (extension.equals("iso")) {
-            templateName = jobs.get(jobId).getTmpltName().trim().replace(" ", "_");
-        } else {
-            templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes()).toString();
-        }
-
-        // run script to mv the temporary template file to the final template
-        // file
-        String templateFilename = templateName + "." + extension;
-        dnld.setTmpltPath(finalResourcePath + "/" + templateFilename);
-        scr.add("-n", templateFilename);
-
-        scr.add("-t", resourcePath);
-        scr.add("-f", td.getDownloadLocalPath()); // this is the temporary
-        // template file downloaded
-        if (dnld.getChecksum() != null && dnld.getChecksum().length() > 1) {
-            scr.add("-c", dnld.getChecksum());
-        }
-        scr.add("-u"); // cleanup
-        String result;
-        result = scr.execute();
-
-        if (result != null) {
-            return result;
-        }
-
-        // Set permissions for the downloaded template
-        File downloadedTemplate = new File(resourcePath + "/" + templateFilename);
-        _storage.setWorldReadableAndWriteable(downloadedTemplate);
-
-        // Set permissions for template/volume.properties
-        String propertiesFile = resourcePath;
-        if (resourceType == ResourceType.TEMPLATE) {
-            propertiesFile += "/template.properties";
-        } else {
-            propertiesFile += "/volume.properties";
-        }
-        File templateProperties = new File(propertiesFile);
-        _storage.setWorldReadableAndWriteable(templateProperties);
-
-        TemplateLocation loc = new TemplateLocation(_storage, resourcePath);
-        try {
-            loc.create(dnld.getId(), true, dnld.getTmpltName());
-        } catch (IOException e) {
-            s_logger.warn("Something is wrong with template location " + resourcePath, e);
-            loc.purge();
-            return "Unable to download due to " + e.getMessage();
-        }
-
-        Iterator<Processor> en = _processors.values().iterator();
-        while (en.hasNext()) {
-            Processor processor = en.next();
-
-            FormatInfo info = null;
-            try {
-                info = processor.process(resourcePath, null, templateName);
-            } catch (InternalErrorException e) {
-                s_logger.error("Template process exception ", e);
-                return e.toString();
-            }
-            if (info != null) {
-                loc.addFormat(info);
-                dnld.setTemplatesize(info.virtualSize);
-                dnld.setTemplatePhysicalSize(info.size);
-                break;
-            }
-        }
-
-        if (!loc.save()) {
-            s_logger.warn("Cleaning up because we're unable to save the formats");
-            loc.purge();
-        }
-
-        return null;
-    }
-
-    @Override
-    public Status getDownloadStatus(String jobId) {
-        DownloadJob job = jobs.get(jobId);
-        if (job != null) {
-            TemplateDownloader td = job.getTemplateDownloader();
-            if (td != null) {
-                return td.getStatus();
-            }
-        }
-        return Status.UNKNOWN;
-    }
-
-    @Override
-    public String downloadS3Template(S3TO s3, long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-            String installPathPrefix, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType) {
-        UUID uuid = UUID.randomUUID();
-        String jobId = uuid.toString();
-
-        URI uri;
-        try {
-            uri = new URI(url);
-        } catch (URISyntaxException e) {
-            throw new CloudRuntimeException("URI is incorrect: " + url);
-        }
-        TemplateDownloader td;
-        if ((uri != null) && (uri.getScheme() != null)) {
-            if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) {
-                td = new S3TemplateDownloader(s3, url, installPathPrefix, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType);
-            } else {
-                throw new CloudRuntimeException("Scheme is not supported " + url);
-            }
-        } else {
-            throw new CloudRuntimeException("Unable to download from URL: " + url);
-        }
-        DownloadJob dj = new DownloadJob(td, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix, resourceType);
-        dj.setTmpltPath(installPathPrefix);
-        jobs.put(jobId, dj);
-        threadPool.execute(td);
-
-        return jobId;
-    }
-
-    @Override
-    public String downloadPublicTemplate(long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum,
-            String installPathPrefix, String templatePath, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType) {
-        UUID uuid = UUID.randomUUID();
-        String jobId = uuid.toString();
-        String tmpDir = installPathPrefix;
-
-        try {
-
-            if (!_storage.mkdirs(tmpDir)) {
-                s_logger.warn("Unable to create " + tmpDir);
-                return "Unable to create " + tmpDir;
-            }
-            // TO DO - define constant for volume properties.
-            File file =
-                    ResourceType.TEMPLATE == resourceType ? _storage.getFile(tmpDir + File.separator + TemplateLocation.Filename) : _storage.getFile(tmpDir + File.separator +
-                            "volume.properties");
-                    if (file.exists()) {
-                        file.delete();
-                    }
-
-                    if (!file.createNewFile()) {
-                        s_logger.warn("Unable to create new file: " + file.getAbsolutePath());
-                        return "Unable to create new file: " + file.getAbsolutePath();
-                    }
-
-                    URI uri;
-                    try {
-                        uri = new URI(url);
-                    } catch (URISyntaxException e) {
-                        throw new CloudRuntimeException("URI is incorrect: " + url);
-                    }
-                    TemplateDownloader td;
-                    if ((uri != null) && (uri.getScheme() != null)) {
-                        if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) {
-                            td = new HttpTemplateDownloader(_storage, url, tmpDir, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType);
-                        } else if (uri.getScheme().equalsIgnoreCase("file")) {
-                            td = new LocalTemplateDownloader(_storage, url, tmpDir, maxTemplateSizeInBytes, new Completion(jobId));
-                        } else if (uri.getScheme().equalsIgnoreCase("scp")) {
-                            td = new ScpTemplateDownloader(_storage, url, tmpDir, maxTemplateSizeInBytes, new Completion(jobId));
-                        } else if (uri.getScheme().equalsIgnoreCase("nfs") || uri.getScheme().equalsIgnoreCase("cifs")) {
-                            td = null;
-                            // TODO: implement this.
-                            throw new CloudRuntimeException("Scheme is not supported " + url);
-                        } else {
-                            throw new CloudRuntimeException("Scheme is not supported " + url);
-                        }
-                    } else {
-                        throw new CloudRuntimeException("Unable to download from URL: " + url);
-                    }
-                    // NOTE the difference between installPathPrefix and templatePath
-                    // here. instalPathPrefix is the absolute path for template
-                    // including mount directory
-                    // on ssvm, while templatePath is the final relative path on
-                    // secondary storage.
-                    DownloadJob dj = new DownloadJob(td, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix, resourceType);
-                    dj.setTmpltPath(templatePath);
-                    jobs.put(jobId, dj);
-                    threadPool.execute(td);
-
-                    return jobId;
-        } catch (IOException e) {
-            s_logger.warn("Unable to download to " + tmpDir, e);
-            return null;
-        }
-    }
-
-    @Override
-    public String getDownloadError(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTemplateDownloader().getDownloadError();
-        }
-        return null;
-    }
-
-    public long getDownloadTemplateSize(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTemplatesize();
-        }
-        return 0;
-    }
-
-    public String getDownloadCheckSum(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getChecksum();
-        }
-        return null;
-    }
-
-    public long getDownloadTemplatePhysicalSize(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTemplatePhysicalSize();
-        }
-        return 0;
-    }
-
-    // @Override
-    public String getDownloadLocalPath(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTemplateDownloader().getDownloadLocalPath();
-        }
-        return null;
-    }
-
-    @Override
-    public int getDownloadPct(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTemplateDownloader().getDownloadPercent();
-        }
-        return 0;
-    }
-
-    public static VMTemplateHostVO.Status convertStatus(Status tds) {
-        switch (tds) {
-        case ABORTED:
-            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
-        case DOWNLOAD_FINISHED:
-            return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS;
-        case IN_PROGRESS:
-            return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS;
-        case NOT_STARTED:
-            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
-        case RECOVERABLE_ERROR:
-            return VMTemplateHostVO.Status.NOT_DOWNLOADED;
-        case UNKNOWN:
-            return VMTemplateHostVO.Status.UNKNOWN;
-        case UNRECOVERABLE_ERROR:
-            return VMTemplateHostVO.Status.DOWNLOAD_ERROR;
-        case POST_DOWNLOAD_FINISHED:
-            return VMTemplateHostVO.Status.DOWNLOADED;
-        default:
-            return VMTemplateHostVO.Status.UNKNOWN;
-        }
-    }
-
-    @Override
-    public com.cloud.storage.VMTemplateHostVO.Status getDownloadStatus2(String jobId) {
-        return convertStatus(getDownloadStatus(jobId));
-    }
-
-    @Override
-    public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd) {
-        ResourceType resourceType = cmd.getResourceType();
-        if (cmd instanceof DownloadProgressCommand) {
-            return handleDownloadProgressCmd(resource, (DownloadProgressCommand)cmd);
-        }
-
-        if (cmd.getUrl() == null) {
-            return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download",
-                    VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-        }
-
-        if (cmd.getName() == null) {
-            return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-        }
-
-        DataStoreTO dstore = cmd.getDataStore();
-        String installPathPrefix = cmd.getInstallPath();
-        // for NFS, we need to get mounted path
-        if (dstore instanceof NfsTO) {
-            installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl()) + File.separator + installPathPrefix;
-        }
-        String user = null;
-        String password = null;
-        if (cmd.getAuth() != null) {
-            user = cmd.getAuth().getUserName();
-            password = cmd.getAuth().getPassword();
-        }
-        // TO DO - Define Volume max size as well
-        long maxDownloadSizeInBytes =
-                (cmd.getMaxDownloadSizeInBytes() == null) ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : (cmd.getMaxDownloadSizeInBytes());
-        String jobId = null;
-        if (dstore instanceof S3TO) {
-            jobId =
-                    downloadS3Template((S3TO)dstore, cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(),
-                            cmd.getChecksum(), installPathPrefix, user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
-        } else {
-            jobId =
-                    downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(),
-                            cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
-        }
-        sleep();
-        if (jobId == null) {
-            return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-        }
-        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
-                getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
-    }
-
-    private void sleep() {
-        try {
-            Thread.sleep(3000);
-        } catch (InterruptedException e) {
-            // ignore
-        }
-    }
-
-    private DownloadAnswer handleDownloadProgressCmd(SecondaryStorageResource resource, DownloadProgressCommand cmd) {
-        String jobId = cmd.getJobId();
-        DownloadAnswer answer;
-        DownloadJob dj = null;
-        if (jobId != null) {
-            dj = jobs.get(jobId);
-        }
-        if (dj == null) {
-            if (cmd.getRequest() == RequestType.GET_OR_RESTART) {
-                DownloadCommand dcmd = new DownloadCommand(cmd);
-                return handleDownloadCommand(resource, dcmd);
-            } else {
-                return new DownloadAnswer("Cannot find job", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.UNKNOWN);
-            }
-        }
-        TemplateDownloader td = dj.getTemplateDownloader();
-        switch (cmd.getRequest()) {
-        case GET_STATUS:
-            break;
-        case ABORT:
-            td.stopDownload();
-            sleep();
-            break;
-        case RESTART:
-            td.stopDownload();
-            sleep();
-            threadPool.execute(td);
-            break;
-        case PURGE:
-            td.stopDownload();
-            answer =
-                    new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId),
-                            getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
-            jobs.remove(jobId);
-            return answer;
-        default:
-            break; // TODO
-        }
-        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
-                getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
-    }
-
-    private String getInstallPath(String jobId) {
-        DownloadJob dj = jobs.get(jobId);
-        if (dj != null) {
-            return dj.getTmpltPath();
-        }
-        return null;
-    }
-
-    private List<String> listVolumes(String rootdir) {
-        List<String> result = new ArrayList<String>();
-
-        Script script = new Script(listVolScr, s_logger);
-        script.add("-r", rootdir);
-        ZfsPathParser zpp = new ZfsPathParser(rootdir);
-        script.execute(zpp);
-        result.addAll(zpp.getPaths());
-        s_logger.info("found " + zpp.getPaths().size() + " volumes" + zpp.getPaths());
-        return result;
-    }
-
-    private List<String> listTemplates(String rootdir) {
-        List<String> result = new ArrayList<String>();
-
-        Script script = new Script(listTmpltScr, s_logger);
-        script.add("-r", rootdir);
-        ZfsPathParser zpp = new ZfsPathParser(rootdir);
-        script.execute(zpp);
-        result.addAll(zpp.getPaths());
-        s_logger.info("found " + zpp.getPaths().size() + " templates" + zpp.getPaths());
-        return result;
-    }
-
-    @Override
-    public Map<String, TemplateProp> gatherTemplateInfo(String rootDir) {
-        Map<String, TemplateProp> result = new HashMap<String, TemplateProp>();
-        String templateDir = rootDir + File.separator + _templateDir;
-
-        if (!_storage.exists(templateDir)) {
-            _storage.mkdirs(templateDir);
-        }
-
-        List<String> publicTmplts = listTemplates(templateDir);
-        for (String tmplt : publicTmplts) {
-            String path = tmplt.substring(0, tmplt.lastIndexOf(File.separator));
-            TemplateLocation loc = new TemplateLocation(_storage, path);
-            try {
-                if (!loc.load()) {
-                    s_logger.warn("Post download installation was not completed for " + path);
-                    // loc.purge();
-                    _storage.cleanup(path, templateDir);
-                    continue;
-                }
-            } catch (IOException e) {
-                s_logger.warn("Unable to load template location " + path, e);
-                continue;
-            }
-
-            TemplateProp tInfo = loc.getTemplateInfo();
-
-            if ((tInfo.getSize() == tInfo.getPhysicalSize()) && (tInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
-                try {
-                    Processor processor = _processors.get("OVA Processor");
-                    OVAProcessor vmdkProcessor = (OVAProcessor)processor;
-                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1));
-                    tInfo.setSize(vSize);
-                    loc.updateVirtualSize(vSize);
-                    loc.save();
-                } catch (Exception e) {
-                    s_logger.error("Unable to get the virtual size of the template: " + tInfo.getInstallPath() + " due to " + e.getMessage());
-                }
-            }
-
-            result.put(tInfo.getTemplateName(), tInfo);
-            s_logger.debug("Added template name: " + tInfo.getTemplateName() + ", path: " + tmplt);
-        }
-        /*
-        for (String tmplt : isoTmplts) {
-            String tmp[];
-            tmp = tmplt.split("/");
-            String tmpltName = tmp[tmp.length - 2];
-            tmplt = tmplt.substring(tmplt.lastIndexOf("iso/"));
-            TemplateInfo tInfo = new TemplateInfo(tmpltName, tmplt, false);
-            s_logger.debug("Added iso template name: " + tmpltName + ", path: " + tmplt);
-            result.put(tmpltName, tInfo);
-        }
-         */
-        return result;
-    }
-
-    @Override
-    public Map<Long, TemplateProp> gatherVolumeInfo(String rootDir) {
-        Map<Long, TemplateProp> result = new HashMap<Long, TemplateProp>();
-        String volumeDir = rootDir + File.separator + _volumeDir;
-
-        if (!_storage.exists(volumeDir)) {
-            _storage.mkdirs(volumeDir);
-        }
-
-        List<String> vols = listVolumes(volumeDir);
-        for (String vol : vols) {
-            String path = vol.substring(0, vol.lastIndexOf(File.separator));
-            TemplateLocation loc = new TemplateLocation(_storage, path);
-            try {
-                if (!loc.load()) {
-                    s_logger.warn("Post download installation was not completed for " + path);
-                    // loc.purge();
-                    _storage.cleanup(path, volumeDir);
-                    continue;
-                }
-            } catch (IOException e) {
-                s_logger.warn("Unable to load volume location " + path, e);
-                continue;
-            }
-
-            TemplateProp vInfo = loc.getTemplateInfo();
-
-            if ((vInfo.getSize() == vInfo.getPhysicalSize()) && (vInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
-                try {
-                    Processor processor = _processors.get("OVA Processor");
-                    OVAProcessor vmdkProcessor = (OVAProcessor)processor;
-                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.getInstallPath().substring(vInfo.getInstallPath().lastIndexOf(File.separator) + 1));
-                    vInfo.setSize(vSize);
-                    loc.updateVirtualSize(vSize);
-                    loc.save();
-                } catch (Exception e) {
-                    s_logger.error("Unable to get the virtual size of the volume: " + vInfo.getInstallPath() + " due to " + e.getMessage());
-                }
-            }
-
-            result.put(vInfo.getId(), vInfo);
-            s_logger.debug("Added volume name: " + vInfo.getTemplateName() + ", path: " + vol);
-        }
-        return result;
-    }
-
-    public static class ZfsPathParser extends OutputInterpreter {
-        String _parent;
-        List<String> paths = new ArrayList<String>();
-
-        public ZfsPathParser(String parent) {
-            _parent = parent;
-        }
-
-        @Override
-        public String interpret(BufferedReader reader) throws IOException {
-            String line = null;
-            while ((line = reader.readLine()) != null) {
-                paths.add(line);
-            }
-            return null;
-        }
-
-        public List<String> getPaths() {
-            return paths;
-        }
-
-        @Override
-        public boolean drain() {
-            return true;
-        }
-    }
-
-    public DownloadManagerImpl() {
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        _name = name;
-
-        String value = null;
-
-        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
-        if (_storage == null) {
-            value = (String)params.get(StorageLayer.ClassConfigKey);
-            if (value == null) {
-                throw new ConfigurationException("Unable to find the storage layer");
-            }
-
-            Class<StorageLayer> clazz;
-            try {
-                clazz = (Class<StorageLayer>)Class.forName(value);
-                _storage = clazz.newInstance();
-            } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            } catch (InstantiationException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            } catch (IllegalAccessException e) {
-                throw new ConfigurationException("Unable to instantiate " + value);
-            }
-        }
-
-        String inSystemVM = (String)params.get("secondary.storage.vm");
-        if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
-            s_logger.info("DownloadManager: starting additional services since we are inside system vm");
-            startAdditionalServices();
-            blockOutgoingOnPrivate();
-        }
-
-        value = (String)params.get("install.timeout.pergig");
-        installTimeoutPerGig = NumbersUtil.parseInt(value, 15 * 60) * 1000;
-
-        value = (String)params.get("install.numthreads");
-        final int numInstallThreads = NumbersUtil.parseInt(value, 10);
-
-        String scriptsDir = (String)params.get("template.scripts.dir");
-        if (scriptsDir == null) {
-            scriptsDir = "scripts/storage/secondary";
-        }
-
-        listTmpltScr = Script.findScript(scriptsDir, "listvmtmplt.sh");
-        if (listTmpltScr == null) {
-            throw new ConfigurationException("Unable to find the listvmtmplt.sh");
-        }
-        s_logger.info("listvmtmplt.sh found in " + listTmpltScr);
-
-        createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
-        if (createTmpltScr == null) {
-            throw new ConfigurationException("Unable to find createtmplt.sh");
-        }
-        s_logger.info("createtmplt.sh found in " + createTmpltScr);
-
-        listVolScr = Script.findScript(scriptsDir, "listvolume.sh");
-        if (listVolScr == null) {
-            throw new ConfigurationException("Unable to find the listvolume.sh");
-        }
-        s_logger.info("listvolume.sh found in " + listVolScr);
-
-        createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
-        if (createVolScr == null) {
-            throw new ConfigurationException("Unable to find createvolume.sh");
-        }
-        s_logger.info("createvolume.sh found in " + createVolScr);
-
-        _processors = new HashMap<String, Processor>();
-
-        Processor processor = new VhdProcessor();
-        processor.configure("VHD Processor", params);
-        _processors.put("VHD Processor", processor);
-
-        processor = new IsoProcessor();
-        processor.configure("ISO Processor", params);
-        _processors.put("ISO Processor", processor);
-
-        processor = new QCOW2Processor();
-        processor.configure("QCOW2 Processor", params);
-        _processors.put("QCOW2 Processor", processor);
-
-        processor = new OVAProcessor();
-        processor.configure("OVA Processor", params);
-        _processors.put("OVA Processor", processor);
-
-        processor = new VmdkProcessor();
-        processor.configure("VMDK Processor", params);
-        _processors.put("VMDK Processor", processor);
-
-        processor = new RawImageProcessor();
-        processor.configure("Raw Image Processor", params);
-        _processors.put("Raw Image Processor", processor);
-
-        _templateDir = (String)params.get("public.templates.root.dir");
-        if (_templateDir == null) {
-            _templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;
-        }
-        _templateDir += File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
-        _volumeDir = TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + File.separator;
-        // Add more processors here.
-        threadPool = Executors.newFixedThreadPool(numInstallThreads);
-        return true;
-    }
-
-    private void blockOutgoingOnPrivate() {
-        Script command = new Script("/bin/bash", s_logger);
-        String intf = "eth1";
-        command.add("-c");
-        command.add("iptables -A OUTPUT -o " + intf + " -p tcp -m state --state NEW -m tcp --dport " + "80" + " -j REJECT;" + "iptables -A OUTPUT -o " + intf +
-                " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j REJECT;");
-
-        String result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in blocking outgoing to port 80/443 err=" + result);
-            return;
-        }
-    }
-
-    @Override
-    public String getName() {
-        return _name;
-    }
-
-    @Override
-    public boolean start() {
-        return true;
-    }
-
-    @Override
-    public boolean stop() {
-        return true;
-    }
-
-    private void startAdditionalServices() {
-
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 stop; else service httpd stop; fi ");
-        String result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in stopping httpd service err=" + result);
-        }
-        String port = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
-        String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
-
-        command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("iptables -I INPUT -i " + intf + " -p tcp -m state --state NEW -m tcp --dport " + port + " -j ACCEPT;" + "iptables -I INPUT -i " + intf +
-                " -p tcp -m state --state NEW -m tcp --dport " + "443" + " -j ACCEPT;");
-
-        result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in opening up httpd port err=" + result);
-            return;
-        }
-
-        command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
-        result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in starting httpd service err=" + result);
-            return;
-        }
-        command = new Script("mkdir", s_logger);
-        command.add("-p");
-        command.add("/var/www/html/copy/template");
-        result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in creating directory =" + result);
-            return;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManager.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManager.java b/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManager.java
deleted file mode 100755
index be99fea..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/template/UploadManager.java
+++ /dev/null
@@ -1,82 +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.storage.template;
-
-import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
-
-import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
-import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
-import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.UploadAnswer;
-import com.cloud.agent.api.storage.UploadCommand;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.Upload.Status;
-import com.cloud.storage.template.TemplateUploader;
-import com.cloud.utils.component.Manager;
-
-public interface UploadManager extends Manager {
-
-    /**
-     * @param jobId job Id
-     * @return status of the upload job
-     */
-    public TemplateUploader.Status getUploadStatus(String jobId);
-
-    /**
-     * @param jobId job Id
-     * @return status of the upload job
-     */
-    public Status getUploadStatus2(String jobId);
-
-    /**
-     * Get the upload percent of a upload job
-     * @param jobId job Id
-     * @return
-     */
-    public int getUploadPct(String jobId);
-
-    /**
-     * Get the upload error if any
-     * @param jobId job Id
-     * @return
-     */
-    public String getUploadError(String jobId);
-
-    /**
-     * Get the local path for the upload
-     * @param jobId job Id
-     * @return
-    public String getUploadLocalPath(String jobId);
-     */
-
-    /** Handle upload commands from the management server
-     * @param cmd cmd from server
-     * @return answer representing status of upload.
-     */
-    public UploadAnswer handleUploadCommand(SecondaryStorageResource resource, UploadCommand cmd);
-
-    public String getPublicTemplateRepo();
-
-    String uploadPublicTemplate(long id, String url, String name, ImageFormat format, Long accountId, String descr, String cksum, String installPathPrefix, String user,
-        String password, long maxTemplateSizeInBytes);
-
-    CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd);
-
-    DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd);
-
-}


[32/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-2932:
Allow deleting of snapshots that have errored out. Simply mark the removed column as there is no physical clean up required. It can land into error state only from allocated/Creating state
 which are states before creation on primary storage works


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/86cada3b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/86cada3b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/86cada3b

Branch: refs/heads/rbac
Commit: 86cada3b3c1871c45bd206c07f785bf499865d61
Parents: e51d472
Author: Nitin Mehta <ni...@citrix.com>
Authored: Wed Feb 5 17:34:48 2014 -0800
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Wed Feb 5 17:34:48 2014 -0800

----------------------------------------------------------------------
 .../cloudstack/storage/snapshot/XenserverSnapshotStrategy.java  | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86cada3b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
index ad7e0f3..8d6886e 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
@@ -197,6 +197,11 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
             return true;
         }
 
+        if (Snapshot.State.Error.equals(snapshotVO.getState())) {
+            snapshotDao.remove(snapshotId);
+            return true;
+        }
+
         if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) {
             s_logger.debug("delete snapshot on primary storage:");
             snapshotVO.setState(Snapshot.State.Destroyed);


[19/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Review 16080 Move Netscaler plugin from non-oss to oss and upgrade the nitro API to 10.1

Signed-off-by: Hugo Trippaers <ht...@schubergphilis.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/356daf3e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/356daf3e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/356daf3e

Branch: refs/heads/rbac
Commit: 356daf3eed7dd817f07da2b7ef57ced9b0eb6fe7
Parents: 28ac2f7
Author: Syed Ahmed <sa...@cloudops.com>
Authored: Wed Feb 5 14:03:49 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 14:03:49 2014 +0100

----------------------------------------------------------------------
 client/pom.xml                                  |  20 +--
 plugins/network-elements/netscaler/pom.xml      |   8 +-
 .../network/resource/NetscalerResource.java     | 149 ++++++++++---------
 plugins/pom.xml                                 |  12 +-
 4 files changed, 87 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/356daf3e/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 06a6db0..f59e1a0 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -97,6 +97,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-network-netscaler</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+  <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-network-ovs</artifactId>
       <version>${project.version}</version>
     </dependency>
@@ -660,21 +665,6 @@
       </dependencies>
     </profile>
     <profile>
-      <id>netscaler</id>
-      <activation>
-        <property>
-          <name>noredist</name>
-        </property>
-      </activation>
-      <dependencies>
-        <dependency>
-          <groupId>org.apache.cloudstack</groupId>
-          <artifactId>cloud-plugin-network-netscaler</artifactId>
-          <version>${project.version}</version>
-        </dependency>
-      </dependencies>
-    </profile>
-    <profile>
       <id>srx</id>
       <activation>
         <property>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/356daf3e/plugins/network-elements/netscaler/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/pom.xml b/plugins/network-elements/netscaler/pom.xml
index e3a2736..684dd99 100644
--- a/plugins/network-elements/netscaler/pom.xml
+++ b/plugins/network-elements/netscaler/pom.xml
@@ -30,12 +30,12 @@
     <dependency>
         <groupId>com.citrix.netscaler.nitro</groupId>
         <artifactId>nitro</artifactId>
-        <version>10.0.e</version>
+        <version>10.1</version>
     </dependency>
     <dependency>
-      <groupId>com.cloud.com.citrix</groupId>
-      <artifactId>netscaler-sdx</artifactId>
-      <version>1.0</version>
+      <groupId>com.citrix.netscaler.nitro</groupId>
+      <artifactId>sdx_nitro</artifactId>
+      <version>10.1</version>
     </dependency>
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/356daf3e/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
index 54e5d50..043997e 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
@@ -72,10 +72,10 @@ import com.citrix.netscaler.nitro.resource.config.ssl.sslvserver_sslcertkey_bind
 import com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats;
 import com.citrix.netscaler.nitro.service.nitro_service;
 import com.citrix.netscaler.nitro.util.filtervalue;
-import com.citrix.sdx.nitro.resource.config.device_profile;
-import com.citrix.sdx.nitro.resource.config.mps;
-import com.citrix.sdx.nitro.resource.config.ns;
-import com.citrix.sdx.nitro.resource.config.xen_vpx_image;
+import com.citrix.sdx.nitro.resource.config.mps.device_profile;
+import com.citrix.sdx.nitro.resource.config.mps.mps;
+import com.citrix.sdx.nitro.resource.config.ns.ns;
+import com.citrix.sdx.nitro.resource.config.xen.xen_nsvpx_image;
 import com.google.common.collect.Lists;
 import com.google.gson.Gson;
 
@@ -298,7 +298,7 @@ public class NetscalerResource implements ServerResource {
                 apiCallResult = _netscalerService.login();
                 if (apiCallResult.errorcode != 0) {
                     throw new ExecutionException("Failed to log in to Netscaler device at " + _ip + " due to error " + apiCallResult.errorcode + " and message " +
-                        apiCallResult.message);
+                            apiCallResult.message);
                 }
             } else {
                 _netscalerSdxService = new com.citrix.sdx.nitro.service.nitro_service(_ip, "https");
@@ -306,7 +306,7 @@ public class NetscalerResource implements ServerResource {
                 com.citrix.sdx.nitro.resource.base.login login = _netscalerSdxService.login();
                 if (login == null) {
                     throw new ExecutionException("Failed to log in to Netscaler SDX device at " + _ip + " due to error " + apiCallResult.errorcode + " and message " +
-                        apiCallResult.message);
+                            apiCallResult.message);
                 }
             }
         } catch (nitro_exception e) {
@@ -374,7 +374,7 @@ public class NetscalerResource implements ServerResource {
                     throw new ExecutionException("Failed to get the hardware description of the Netscaler device at " + _ip);
                 } else {
                     if ((_deviceName.equalsIgnoreCase("NetscalerMPXLoadBalancer") && nsHw.get_hwdescription().contains("MPX")) ||
-                        (_deviceName.equalsIgnoreCase("NetscalerVPXLoadBalancer") && nsHw.get_hwdescription().contains("NetScaler Virtual Appliance"))) {
+                            (_deviceName.equalsIgnoreCase("NetscalerVPXLoadBalancer") && nsHw.get_hwdescription().contains("NetScaler Virtual Appliance"))) {
                         return;
                     }
                     throw new ExecutionException("Netscalar device type specified does not match with the actuall device type.");
@@ -510,7 +510,7 @@ public class NetscalerResource implements ServerResource {
                     String nsVirtualServerName = generateNSVirtualServerName(loadBalancer.getSrcIp(), loadBalancer.getSrcPort());
 
                     com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings =
-                        com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
+                            com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
 
                     if (serviceBindings != null) {
                         for (DestinationTO destination : loadBalancer.getDestinations()) {
@@ -635,21 +635,21 @@ public class NetscalerResource implements ServerResource {
                                 apiCallResult = com.citrix.netscaler.nitro.resource.config.basic.service.add(_netscalerService, newService);
                                 if (apiCallResult.errorcode != 0) {
                                     throw new ExecutionException("Failed to create service " + nsServiceName + " using server " + nsServerName + " due to" +
-                                        apiCallResult.message);
+                                            apiCallResult.message);
                                 }
                             }
 
                             //bind service to load balancing virtual server
                             if (!nsServiceBindingExists(nsVirtualServerName, nsServiceName)) {
                                 com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding svcBinding =
-                                    new com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding();
+                                        new com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding();
                                 svcBinding.set_name(nsVirtualServerName);
                                 svcBinding.set_servicename(nsServiceName);
                                 apiCallResult = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.add(_netscalerService, svcBinding);
 
                                 if (apiCallResult.errorcode != 0) {
                                     throw new ExecutionException("Failed to bind service: " + nsServiceName + " to the lb virtual server: " + nsVirtualServerName +
-                                        " on Netscaler device");
+                                            " on Netscaler device");
                                 }
                             }
 
@@ -692,7 +692,7 @@ public class NetscalerResource implements ServerResource {
                                             String intermediateCertFileName = intermediateCertKeyName + ".pem";
 
                                             if (!SSL.isSslCertKeyPresent(_netscalerService, intermediateCertKeyName)) {
-                                                byte[] certData = intermediateCert.getEncoded();
+                                                intermediateCert.getEncoded();
                                                 StringWriter textWriter = new StringWriter();
                                                 PEMWriter pemWriter = new PEMWriter(textWriter);
                                                 pemWriter.writeObject(intermediateCert);
@@ -735,13 +735,13 @@ public class NetscalerResource implements ServerResource {
 
                             if (s_logger.isDebugEnabled()) {
                                 s_logger.debug("Successfully added LB destination: " + destination.getDestIp() + ":" + destination.getDestPort() + " to load balancer " +
-                                    srcIp + ":" + srcPort);
+                                        srcIp + ":" + srcPort);
                             }
 
                         } else {
                             // remove a destination from the deployed load balancing rule
                             com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings =
-                                com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
+                                    com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
                             if (serviceBindings != null) {
                                 for (com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
                                     if (nsServiceName.equalsIgnoreCase(binding.get_servicename())) {
@@ -749,7 +749,7 @@ public class NetscalerResource implements ServerResource {
                                         apiCallResult = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.delete(_netscalerService, binding);
                                         if (apiCallResult.errorcode != 0) {
                                             throw new ExecutionException("Failed to delete the binding between the virtual server: " + nsVirtualServerName +
-                                                " and service:" + nsServiceName + " due to" + apiCallResult.message);
+                                                    " and service:" + nsServiceName + " due to" + apiCallResult.message);
                                         }
 
                                         // check if service is bound to any other virtual server
@@ -780,7 +780,7 @@ public class NetscalerResource implements ServerResource {
                     if (lbserver != null) {
                         //unbind the all services associated with this virtual server
                         com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings =
-                            com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
+                                com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
 
                         if (serviceBindings != null) {
                             for (com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
@@ -788,11 +788,11 @@ public class NetscalerResource implements ServerResource {
                                 apiCallResult = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.delete(_netscalerService, binding);
                                 if (apiCallResult.errorcode != 0) {
                                     throw new ExecutionException("Failed to unbind service from the lb virtual server: " + nsVirtualServerName + " due to " +
-                                        apiCallResult.message);
+                                            apiCallResult.message);
                                 }
 
                                 com.citrix.netscaler.nitro.resource.config.basic.service svc =
-                                    com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, serviceName);
+                                        com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, serviceName);
                                 String nsServerName = svc.get_servername();
 
                                 // check if service is bound to any other virtual server
@@ -830,8 +830,8 @@ public class NetscalerResource implements ServerResource {
 
                     // unbind before deleting
                     if (nsVirtualServerExists(nsVirtualServerName) &&
-                        SSL.isSslCertKeyPresent(_netscalerService, certKeyName) &&
-                        SSL.isBoundToVserver(_netscalerService, certKeyName, nsVirtualServerName)) {
+                            SSL.isSslCertKeyPresent(_netscalerService, certKeyName) &&
+                            SSL.isBoundToVserver(_netscalerService, certKeyName, nsVirtualServerName)) {
                         SSL.unbindCertKeyFromVserver(_netscalerService, certKeyName, nsVirtualServerName);
                     }
 
@@ -846,7 +846,7 @@ public class NetscalerResource implements ServerResource {
                      * Check and delete intermediate certs:
                      * we can delete an intermediate cert if no other
                      * cert references it as the athority
-                    */
+                     */
 
                     if (sslCert.getChain() != null) {
                         List<Certificate> chainList = CertificateHelper.parseChain(sslCert.getChain());
@@ -858,7 +858,7 @@ public class NetscalerResource implements ServerResource {
                             String intermediateCertFileName = intermediateCertKeyName + ".pem";
 
                             if (SSL.isSslCertKeyPresent(_netscalerService, intermediateCertKeyName) &&
-                                !SSL.isCaforCerts(_netscalerService, intermediateCertKeyName)) {
+                                    !SSL.isCaforCerts(_netscalerService, intermediateCertKeyName)) {
                                 SSL.deleteSslCertKey(_netscalerService, intermediateCertKeyName);
                                 SSL.deleteCertFile(_ip, _username, _password, intermediateCertFileName);
                             } else {
@@ -914,8 +914,8 @@ public class NetscalerResource implements ServerResource {
             ns_obj.set_password(password);
 
             // configure VPX instances with defaults
-            ns_obj.set_feature_license("Standard");
-            ns_obj.set_memory_total(new Double(2048));
+            ns_obj.set_license("Standard");
+            ns_obj.set_vm_memory_total(new Double(2048));
             ns_obj.set_throughput(new Double(1000));
             ns_obj.set_pps(new Double(1000000));
             ns_obj.set_number_of_ssl_cores(0);
@@ -924,17 +924,17 @@ public class NetscalerResource implements ServerResource {
             device_profile[] profiles = device_profile.get(_netscalerSdxService);
             if (!(profiles != null && profiles.length >= 1)) {
                 new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip +
-                    " as there are no admin profile to use for creating VPX."));
+                        " as there are no admin profile to use for creating VPX."));
             }
             String profileName = profiles[0].get_name();
-            ns_obj.set_nsroot_profile(profileName);
+            ns_obj.set_profile_name(profileName);
 
             // use the first VPX image of the available VPX images on the SDX to create an instance of VPX
             // TODO: should enable the option to choose the template while adding the SDX device in to CloudStack
-            xen_vpx_image[] vpxImages = xen_vpx_image.get(_netscalerSdxService);
+            xen_nsvpx_image[] vpxImages = xen_nsvpx_image.get(_netscalerSdxService);
             if (!(vpxImages != null && vpxImages.length >= 1)) {
                 new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip +
-                    " as there are no VPX images on SDX to use for creating VPX."));
+                        " as there are no VPX images on SDX to use for creating VPX."));
             }
             String imageName = vpxImages[0].get_file_name();
             ns_obj.set_image_name(imageName);
@@ -955,7 +955,7 @@ public class NetscalerResource implements ServerResource {
             // wait for VPX instance to start-up
             long startTick = System.currentTimeMillis();
             long startWaitMilliSeconds = 600000;
-            while (!newVpx.get_ns_state().equalsIgnoreCase("up") && System.currentTimeMillis() - startTick < startWaitMilliSeconds) {
+            while (!newVpx.get_state().equalsIgnoreCase("up") && System.currentTimeMillis() - startTick < startWaitMilliSeconds) {
                 try {
                     Thread.sleep(10000);
                 } catch (InterruptedException e) {
@@ -966,7 +966,7 @@ public class NetscalerResource implements ServerResource {
             }
 
             // if vpx instance never came up then error out
-            if (!newVpx.get_ns_state().equalsIgnoreCase("up")) {
+            if (!newVpx.get_state().equalsIgnoreCase("up")) {
                 return new Answer(cmd, new ExecutionException("Failed to start VPX instance " + vpxName + " created on the netscaler SDX device " + _ip));
             }
 
@@ -1036,13 +1036,13 @@ public class NetscalerResource implements ServerResource {
             }
 
             return new CreateLoadBalancerApplianceAnswer(cmd, true, "provisioned VPX instance", "NetscalerVPXLoadBalancer", "Netscaler", new NetscalerResource(),
-                publicIf, privateIf, _username, _password);
+                    publicIf, privateIf, _username, _password);
         } catch (Exception e) {
             if (shouldRetry(numRetries)) {
                 return retry(cmd, numRetries);
             }
             return new CreateLoadBalancerApplianceAnswer(cmd, false, "failed to provisioned VPX instance due to " + e.getMessage(), null, null, null, null, null, null,
-                null);
+                    null);
         }
     }
 
@@ -1108,8 +1108,7 @@ public class NetscalerResource implements ServerResource {
                             // Unbind GSLB service with GSLB virtual server
                             GSLB.deleteVserverServiceBinding(_netscalerService, serviceName, vserverName);
 
-                            // delete 'gslbservice' object
-                            gslbservice service = GSLB.getServiceObject(_netscalerService, serviceName);
+                            GSLB.getServiceObject(_netscalerService, serviceName);
                             GSLB.deleteService(_netscalerService, serviceName);
 
                             // delete the GSLB service monitor
@@ -1288,7 +1287,7 @@ public class NetscalerResource implements ServerResource {
 
         // create a 'gslbvserver' object representing a globally load balanced service
         private static void
-            createVirtualServer(nitro_service client, String vserverName, String lbMethod, String persistenceType, long persistenceId, String serviceType)
+        createVirtualServer(nitro_service client, String vserverName, String lbMethod, String persistenceType, long persistenceId, String serviceType)
                 throws ExecutionException {
             try {
                 gslbvserver vserver;
@@ -1398,7 +1397,7 @@ public class NetscalerResource implements ServerResource {
 
         // update 'gslbvserver' object representing a globally load balanced service
         private static void updateVirtualServer(nitro_service client, String vserverName, String lbMethod, String persistenceType, String serviceType)
-            throws ExecutionException {
+                throws ExecutionException {
             try {
                 gslbvserver vServer = getVserverObject(client, vserverName);
                 if (vServer != null) {
@@ -1421,7 +1420,7 @@ public class NetscalerResource implements ServerResource {
 
         // create, delete, update, get the GSLB services
         private static void createService(nitro_service client, String serviceName, String serviceType, String serviceIp, String servicePort, String siteName)
-            throws ExecutionException {
+                throws ExecutionException {
             try {
                 gslbservice service;
                 service = getServiceObject(client, serviceName);
@@ -1493,7 +1492,7 @@ public class NetscalerResource implements ServerResource {
         }
 
         private static void updateService(nitro_service client, String serviceName, String serviceType, String publicIp, String publicPort, String siteName)
-            throws ExecutionException {
+                throws ExecutionException {
             try {
                 gslbservice service;
                 service = getServiceObject(client, serviceName);
@@ -1688,7 +1687,7 @@ public class NetscalerResource implements ServerResource {
                 }
             } catch (Exception e) {
                 s_logger.debug("Failed to delete GSLB monitor " + monitorName + " and GSLB service " + serviceName + " binding due to " + e.getMessage() +
-                    " but moving on ..., will be cleaned up as part of GSLB " + " service delete any way..");
+                        " but moving on ..., will be cleaned up as part of GSLB " + " service delete any way..");
             }
         }
 
@@ -2357,7 +2356,7 @@ public class NetscalerResource implements ServerResource {
                 // if Vlan to interface binding does not exist then ignore the exception and proceed
                 if (!(e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS)) {
                     throw new ExecutionException("Failed to unbind vlan from the interface while shutdown of guest network on the Netscaler device due to " +
-                        e.getMessage());
+                            e.getMessage());
                 }
             }
 
@@ -2380,7 +2379,10 @@ public class NetscalerResource implements ServerResource {
 
             // remove subnet IP
             try {
-                nsip subnetIp = nsip.get(_netscalerService, vlanSelfIp);
+                nsip _vlanSelfIp = new nsip();
+                _vlanSelfIp.set_ipaddress(vlanSelfIp);
+
+                nsip subnetIp = nsip.get(_netscalerService, _vlanSelfIp);
                 apiCallResult = nsip.delete(_netscalerService, subnetIp);
                 if (apiCallResult.errorcode != 0) {
                     throw new ExecutionException("Failed to remove subnet ip:" + vlanSelfIp + " from the NetScaler device due to" + apiCallResult.message);
@@ -2425,9 +2427,12 @@ public class NetscalerResource implements ServerResource {
         }
     }
 
-    private boolean nsSnipExists(String subnetIP) throws ExecutionException {
+    private boolean nsSnipExists(String subnetIp) throws ExecutionException {
         try {
-            nsip snip = nsip.get(_netscalerService, subnetIP);
+            nsip _subnetIp = new nsip();
+            _subnetIp.set_ipaddress(subnetIp);
+
+            nsip snip = nsip.get(_netscalerService, _subnetIp);
             return (snip != null);
         } catch (nitro_exception e) {
             if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
@@ -2585,7 +2590,7 @@ public class NetscalerResource implements ServerResource {
     private boolean nsServiceBindingExists(String lbVirtualServer, String serviceName) throws ExecutionException {
         try {
             com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings =
-                com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, lbVirtualServer);
+                    com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, lbVirtualServer);
             if (serviceBindings != null) {
                 for (com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
                     if (serviceName.equalsIgnoreCase(binding.get_servicename())) {
@@ -2603,17 +2608,17 @@ public class NetscalerResource implements ServerResource {
 
     private boolean isServiceGroupBoundToVirtualServer(String nsVirtualServerName, String serviceGroupName) throws ExecutionException {
 
-        lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding();
+        new lbvserver_servicegroup_binding();
 
         try {
             lbvserver_servicegroup_binding[] result =
-                lbvserver_servicegroup_binding.get_filtered(_netscalerService, nsVirtualServerName, "servicegroupname:" + serviceGroupName);
+                    lbvserver_servicegroup_binding.get_filtered(_netscalerService, nsVirtualServerName, "servicegroupname:" + serviceGroupName);
             if (result != null && result.length > 0) {
                 return true;
             }
         } catch (Exception e) {
             throw new ExecutionException("Failed to verify lb vserver " + nsVirtualServerName + "and servicegrop " + serviceGroupName + " binding exists due to " +
-                e.getMessage());
+                    e.getMessage());
         }
         return false;
 
@@ -2647,7 +2652,7 @@ public class NetscalerResource implements ServerResource {
                 if (NetUtils.sameSubnet(vlanSelfIp, server.get_ipaddress(), vlanNetmask)) {
                     // first remove services associated with this server
                     com.citrix.netscaler.nitro.resource.config.basic.service serveicesList[] =
-                        com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService);
+                            com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService);
                     if (serveicesList != null) {
                         for (com.citrix.netscaler.nitro.resource.config.basic.service svc : serveicesList) {
                             if (svc.get_servername().equals(server.get_ipaddress())) {
@@ -2685,7 +2690,7 @@ public class NetscalerResource implements ServerResource {
         if ((stickyPolicies != null) && (stickyPolicies.length > 0) && (stickyPolicies[0] != null)) {
             StickinessPolicyTO stickinessPolicy = stickyPolicies[0];
             if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName()) ||
-                (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName()))) {
+                    (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName()))) {
                 nsProtocol = "HTTP";
                 return nsProtocol;
             }
@@ -2706,7 +2711,7 @@ public class NetscalerResource implements ServerResource {
     }
 
     private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies,
-        AutoScaleVmGroupTO vmGroupTO) throws ExecutionException {
+            AutoScaleVmGroupTO vmGroupTO) throws ExecutionException {
         try {
             String lbMethod;
             if ("roundrobin".equalsIgnoreCase(lbAlgorithm)) {
@@ -2724,7 +2729,7 @@ public class NetscalerResource implements ServerResource {
             if (vserver != null) {
                 if (!vserver.get_servicetype().equalsIgnoreCase(protocol)) {
                     throw new ExecutionException("Can not update virtual server:" + virtualServerName + " as current protocol:" + vserver.get_servicetype() +
-                        " of virtual server is different from the " + " intended protocol:" + protocol);
+                            " of virtual server is different from the " + " intended protocol:" + protocol);
                 }
                 vserverExisis = true;
             }
@@ -2826,7 +2831,7 @@ public class NetscalerResource implements ServerResource {
             if (csMonitor != null) {
                 if (!csMonitor.get_type().equalsIgnoreCase(lbProtocol)) {
                     throw new ExecutionException("Can not update monitor :" + nsMonitorName + " as current protocol:" + csMonitor.get_type() +
-                        " of monitor is different from the " + " intended protocol:" + lbProtocol);
+                            " of monitor is different from the " + " intended protocol:" + lbProtocol);
                 }
                 csMonitorExisis = true;
             }
@@ -2847,7 +2852,7 @@ public class NetscalerResource implements ServerResource {
                 csMon.set_failureretries(hcp.getUnhealthThresshold());
                 csMon.set_successretries(hcp.getHealthcheckThresshold());
                 s_logger.debug("Monitor properites going to get created :interval :: " + csMon.get_interval() + "respTimeOUt:: " + csMon.get_resptimeout() +
-                    "failure retires(unhealththresshold) :: " + csMon.get_failureretries() + "successtries(healththresshold) ::" + csMon.get_successretries());
+                        "failure retires(unhealththresshold) :: " + csMon.get_failureretries() + "successtries(healththresshold) ::" + csMon.get_successretries());
                 lbmonitor.add(_netscalerService, csMon);
             } else {
                 s_logger.debug("Monitor :" + nsMonitorName + " is already existing. Skipping to delete and create it");
@@ -2866,7 +2871,7 @@ public class NetscalerResource implements ServerResource {
             serviceObject = com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, nsServiceName);
             if (serviceObject != null) {
                 com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding serviceMonitor =
-                    new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
+                        new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
                 serviceMonitor.set_monitor_name(nsMonitorName);
                 serviceMonitor.set_name(nsServiceName);
                 serviceMonitor.set_monstate("ENABLED");
@@ -2889,7 +2894,7 @@ public class NetscalerResource implements ServerResource {
 
             if (serviceObject != null) {
                 com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding serviceMonitor =
-                    new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
+                        new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
                 serviceMonitor.set_monitor_name(nsMonitorName);
                 serviceMonitor.set_name(nsServiceName);
                 s_logger.debug("Trying to unbind  the monitor :" + nsMonitorName + " from the service :" + nsServiceName);
@@ -2955,7 +2960,7 @@ public class NetscalerResource implements ServerResource {
         int srcPort = loadBalancerTO.getSrcPort();
         String lbProtocol = getNetScalerProtocol(loadBalancerTO);
         String lbAlgorithm = loadBalancerTO.getAlgorithm();
-        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
+        generateAutoScaleVmGroupIdentifier(loadBalancerTO);
         String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
         AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
         if (s_logger.isDebugEnabled()) {
@@ -3008,7 +3013,7 @@ public class NetscalerResource implements ServerResource {
     private synchronized boolean removeAutoScaleConfig(LoadBalancerTO loadBalancerTO) throws Exception, ExecutionException {
         String srcIp = loadBalancerTO.getSrcIp();
         int srcPort = loadBalancerTO.getSrcPort();
-        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
+        generateAutoScaleVmGroupIdentifier(loadBalancerTO);
 
         String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
         String serviceGroupName = generateAutoScaleServiceGroupName(loadBalancerTO);
@@ -3064,7 +3069,7 @@ public class NetscalerResource implements ServerResource {
         AutoScaleVmProfileTO profileTO = vmGroupTO.getProfile();
         List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
         int interval = vmGroupTO.getInterval();
-        List<Pair<String, String>> counterParams = profileTO.getCounterParamList();
+        profileTO.getCounterParamList();
         String snmpCommunity = null;
         int snmpPort = DEFAULT_SNMP_PORT;
         long cur_prirotiy = 1;
@@ -3156,7 +3161,7 @@ public class NetscalerResource implements ServerResource {
             // add autoscale action lb_scaleUpAction provision -vserver lb -profilename lb_asprofile -params
             // -lbruleid=1234&command=deployvm&zoneid=10&templateid=5&serviceofferingid=3- -quiettime 300
             com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleUpAction =
-                new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
+                    new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
             try {
                 scaleUpAction.set_name(scaleUpActionName);
                 scaleUpAction.set_type("SCALE_UP"); // TODO: will this be called provision?
@@ -3165,10 +3170,10 @@ public class NetscalerResource implements ServerResource {
                 scaleUpAction.set_profilename(profileName);
                 scaleUpAction.set_quiettime(scaleUpQuietTime);
                 String scaleUpParameters =
-                    "command=deployVirtualMachine" + "&" + ApiConstants.ZONE_ID + "=" + profileTO.getZoneId() + "&" + ApiConstants.SERVICE_OFFERING_ID + "=" +
-                        profileTO.getServiceOfferingId() + "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId() + "&" + ApiConstants.DISPLAY_NAME + "=" +
-                        profileTO.getVmName() + "&" + ((profileTO.getNetworkId() == null) ? "" : (ApiConstants.NETWORK_IDS + "=" + profileTO.getNetworkId() + "&")) +
-                        ((profileTO.getOtherDeployParams() == null) ? "" : (profileTO.getOtherDeployParams() + "&")) + "lbruleid=" + loadBalancerTO.getUuid();
+                        "command=deployVirtualMachine" + "&" + ApiConstants.ZONE_ID + "=" + profileTO.getZoneId() + "&" + ApiConstants.SERVICE_OFFERING_ID + "=" +
+                                profileTO.getServiceOfferingId() + "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId() + "&" + ApiConstants.DISPLAY_NAME + "=" +
+                                profileTO.getVmName() + "&" + ((profileTO.getNetworkId() == null) ? "" : (ApiConstants.NETWORK_IDS + "=" + profileTO.getNetworkId() + "&")) +
+                                ((profileTO.getOtherDeployParams() == null) ? "" : (profileTO.getOtherDeployParams() + "&")) + "lbruleid=" + loadBalancerTO.getUuid();
                 scaleUpAction.set_parameters(scaleUpParameters);
                 autoscaleaction.add(_netscalerService, scaleUpAction);
             } catch (Exception e) {
@@ -3178,7 +3183,7 @@ public class NetscalerResource implements ServerResource {
             }
 
             com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction =
-                new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
+                    new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
             Integer destroyVmGracePeriod = profileTO.getDestroyVmGraceperiod();
             try {
                 scaleDownAction.set_name(scaleDownActionName);
@@ -3200,13 +3205,13 @@ public class NetscalerResource implements ServerResource {
             /* Create min member policy */
             String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier);
             String minMemberPolicyExp =
-                "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)";
+                    "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)";
             addAutoScalePolicy(timerName, minMemberPolicyName, cur_prirotiy++, minMemberPolicyExp, scaleUpActionName, interval, interval, isCleanUp);
 
             /* Create max member policy */
             String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier);
             String maxMemberPolicyExp =
-                "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
+                    "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
             addAutoScalePolicy(timerName, maxMemberPolicyName, cur_prirotiy++, maxMemberPolicyExp, scaleDownActionName, interval, interval, isCleanUp);
 
             /* Create Counters */
@@ -3336,12 +3341,12 @@ public class NetscalerResource implements ServerResource {
                 if (isScaleUpPolicy(autoScalePolicyTO)) {
                     action = scaleUpActionName;
                     String scaleUpCondition =
-                        "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
+                            "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
                     policyExpression = scaleUpCondition + " && " + policyExpression;
                 } else {
                     action = scaleDownActionName;
                     String scaleDownCondition =
-                        "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)";
+                            "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)";
                     policyExpression = scaleDownCondition + " && " + policyExpression;
                 }
 
@@ -3409,7 +3414,7 @@ public class NetscalerResource implements ServerResource {
             /* Delete AutoScale Config */
             // Delete AutoScale ScaleDown action
             com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction =
-                new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
+                    new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
             try {
                 scaleDownAction.set_name(scaleDownActionName);
                 autoscaleaction.delete(_netscalerService, scaleDownAction);
@@ -3421,7 +3426,7 @@ public class NetscalerResource implements ServerResource {
 
             // Delete AutoScale ScaleUp action
             com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleUpAction =
-                new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
+                    new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
             try {
                 scaleUpAction.set_name(scaleUpActionName);
                 autoscaleaction.delete(_netscalerService, scaleUpAction);
@@ -3504,7 +3509,7 @@ public class NetscalerResource implements ServerResource {
     }
 
     private synchronized void addAutoScalePolicy(String timerName, String policyName, long priority, String policyExpression, String action, int duration, int interval,
-        boolean isCleanUp) throws Exception {
+            boolean isCleanUp) throws Exception {
         // Adding a autoscale policy
         // add timer policy lb_policy_scaleUp_cpu_mem -rule - (SYS.CUR_VSERVER.METRIC_TABLE(cpu).AVG_VAL.GT(80)-
         // -action lb_scaleUpAction
@@ -3572,7 +3577,7 @@ public class NetscalerResource implements ServerResource {
     }
 
     private boolean isAutoScaleSupportedInNetScaler() throws ExecutionException {
-        autoscaleprofile autoscaleProfile = new autoscaleprofile();
+        new autoscaleprofile();
         try {
             autoscaleprofile.get(_netscalerService);
         } catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/356daf3e/plugins/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 37382de..b1bafee 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -47,6 +47,7 @@
     <module>network-elements/ovs</module>
     <module>network-elements/juniper-contrail</module>
     <module>network-elements/palo-alto</module>
+    <module>network-elements/netscaler</module>
     <module>network-elements/nicira-nvp</module>
     <module>network-elements/bigswitch-vns</module>
     <module>network-elements/midonet</module>
@@ -137,17 +138,6 @@
       </modules>
     </profile>
     <profile>
-      <id>netscaler</id>
-      <activation>
-        <property>
-          <name>noredist</name>
-        </property>
-      </activation>
-      <modules>
-        <module>network-elements/netscaler</module>
-      </modules>
-    </profile>
-    <profile>
       <id>srx</id>
       <activation>
         <property>


[20/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
Add versions to the reporting plugins, prevents maven from complaining about it


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/884c03f9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/884c03f9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/884c03f9

Branch: refs/heads/rbac
Commit: 884c03f90de0732d16d75b3275b0ea4f72fdaf71
Parents: 356daf3
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Wed Feb 5 14:18:07 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Feb 5 14:18:07 2014 +0100

----------------------------------------------------------------------
 pom.xml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/884c03f9/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1d2304f..9dbd72b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,6 +88,8 @@
     <cs.jna.version>4.0.0</cs.jna.version>
     <cs.checkstyle.version>2.11</cs.checkstyle.version>
     <cs.mycila.license.version>2.5</cs.mycila.license.version>
+    <cs.findbugs.version>2.5.3</cs.findbugs.version>
+    <cs.javadoc.version>2.9.1</cs.javadoc.version>
   </properties>
 
   <distributionManagement>
@@ -865,7 +867,7 @@
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>findbugs-maven-plugin</artifactId>
-          <version>2.5.3</version>
+          <version>${cs.findbugs.version}</version>
           <configuration>
             <effort>Max</effort>
             <threshold>High</threshold>
@@ -890,6 +892,7 @@
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>findbugs-maven-plugin</artifactId>
+        <version>${cs.findbugs.version}</version>
         <configuration>
           <threshold>Low</threshold><!-- High|Normal|Low|Exp|Ignore -->
           <effort>Default</effort><!-- Min|Default|Max -->
@@ -898,6 +901,7 @@
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
+         <version>${cs.javadoc.version}</version>
          <configuration>
            <minmemory>128m</minmemory>
            <maxmemory>1g</maxmemory>


[07/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
new file mode 100755
index 0000000..9782c2e
--- /dev/null
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -0,0 +1,2430 @@
+// 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.storage.resource;
+
+import static com.cloud.utils.S3Utils.mputFile;
+import static com.cloud.utils.S3Utils.putFile;
+import static com.cloud.utils.StringUtils.join;
+import static java.lang.String.format;
+import static java.util.Arrays.asList;
+import static org.apache.commons.lang.StringUtils.substringAfterLast;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.log4j.Logger;
+
+import com.amazonaws.services.s3.model.S3ObjectSummary;
+
+import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
+import org.apache.cloudstack.storage.command.CopyCmdAnswer;
+import org.apache.cloudstack.storage.command.CopyCommand;
+import org.apache.cloudstack.storage.command.DeleteCommand;
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.command.DownloadProgressCommand;
+import org.apache.cloudstack.storage.template.DownloadManager;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl.ZfsPathParser;
+import org.apache.cloudstack.storage.template.UploadManager;
+import org.apache.cloudstack.storage.template.UploadManagerImpl;
+import org.apache.cloudstack.storage.to.SnapshotObjectTO;
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckHealthAnswer;
+import com.cloud.agent.api.CheckHealthCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.ComputeChecksumCommand;
+import com.cloud.agent.api.DeleteSnapshotsDirCommand;
+import com.cloud.agent.api.GetStorageStatsAnswer;
+import com.cloud.agent.api.GetStorageStatsCommand;
+import com.cloud.agent.api.PingCommand;
+import com.cloud.agent.api.PingStorageCommand;
+import com.cloud.agent.api.ReadyAnswer;
+import com.cloud.agent.api.ReadyCommand;
+import com.cloud.agent.api.SecStorageFirewallCfgCommand;
+import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
+import com.cloud.agent.api.SecStorageSetupAnswer;
+import com.cloud.agent.api.SecStorageSetupCommand;
+import com.cloud.agent.api.SecStorageVMSetupCommand;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupSecondaryStorageCommand;
+import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
+import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.ListTemplateAnswer;
+import com.cloud.agent.api.storage.ListTemplateCommand;
+import com.cloud.agent.api.storage.ListVolumeAnswer;
+import com.cloud.agent.api.storage.ListVolumeCommand;
+import com.cloud.agent.api.storage.UploadCommand;
+import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.agent.api.to.DataStoreTO;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.agent.api.to.SwiftTO;
+import com.cloud.exception.InternalErrorException;
+import com.cloud.host.Host;
+import com.cloud.host.Host.Type;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.resource.ServerResourceBase;
+import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.StorageLayer;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.template.OVAProcessor;
+import com.cloud.storage.template.Processor;
+import com.cloud.storage.template.Processor.FormatInfo;
+import com.cloud.storage.template.QCOW2Processor;
+import com.cloud.storage.template.RawImageProcessor;
+import com.cloud.storage.template.TemplateLocation;
+import com.cloud.storage.template.TemplateProp;
+import com.cloud.storage.template.VhdProcessor;
+import com.cloud.storage.template.VmdkProcessor;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.S3Utils;
+import com.cloud.utils.S3Utils.FileNamingStrategy;
+import com.cloud.utils.SwiftUtil;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.Script;
+import com.cloud.vm.SecondaryStorageVm;
+
+public class NfsSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
+
+    private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResource.class);
+
+    private static final String TEMPLATE_ROOT_DIR = "template/tmpl";
+    private static final String VOLUME_ROOT_DIR = "volumes";
+
+    int _timeout;
+
+    public int getTimeout() {
+        return _timeout;
+    }
+
+    public void setTimeout(int timeout) {
+        _timeout = timeout;
+    }
+
+    String _instance;
+    String _dc;
+    String _pod;
+    String _guid;
+    String _role;
+    Map<String, Object> _params;
+    protected StorageLayer _storage;
+    protected boolean _inSystemVM = false;
+    boolean _sslCopy = false;
+
+    protected DownloadManager _dlMgr;
+    protected UploadManager _upldMgr;
+    private String _configSslScr;
+    private String _configAuthScr;
+    private String _configIpFirewallScr;
+    private String _publicIp;
+    private String _hostname;
+    private String _localgw;
+    private String _eth1mask;
+    private String _eth1ip;
+    private String _storageIp;
+    private String _storageNetmask;
+    private String _storageGateway;
+    private final List<String> nfsIps = new ArrayList<String>();
+    protected String _parent = "/mnt/SecStorage";
+    final private String _tmpltpp = "template.properties";
+    protected String createTemplateFromSnapshotXenScript;
+
+    public void setParentPath(String path) {
+        _parent = path;
+    }
+
+    public String getMountingRoot() {
+        return _parent;
+    }
+
+    @Override
+    public void disconnected() {
+    }
+
+    public void setInSystemVM(boolean inSystemVM) {
+        _inSystemVM = inSystemVM;
+    }
+
+    @Override
+    public Answer executeRequest(Command cmd) {
+        if (cmd instanceof DownloadProgressCommand) {
+            return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
+        } else if (cmd instanceof DownloadCommand) {
+            return execute((DownloadCommand)cmd);
+        } else if (cmd instanceof UploadCommand) {
+            return _upldMgr.handleUploadCommand(this, (UploadCommand)cmd);
+        } else if (cmd instanceof CreateEntityDownloadURLCommand) {
+            return _upldMgr.handleCreateEntityURLCommand((CreateEntityDownloadURLCommand)cmd);
+        } else if (cmd instanceof DeleteEntityDownloadURLCommand) {
+            return _upldMgr.handleDeleteEntityDownloadURLCommand((DeleteEntityDownloadURLCommand)cmd);
+        } else if (cmd instanceof GetStorageStatsCommand) {
+            return execute((GetStorageStatsCommand)cmd);
+        } else if (cmd instanceof CheckHealthCommand) {
+            return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
+        } else if (cmd instanceof ReadyCommand) {
+            return new ReadyAnswer((ReadyCommand)cmd);
+        } else if (cmd instanceof SecStorageFirewallCfgCommand) {
+            return execute((SecStorageFirewallCfgCommand)cmd);
+        } else if (cmd instanceof SecStorageVMSetupCommand) {
+            return execute((SecStorageVMSetupCommand)cmd);
+        } else if (cmd instanceof SecStorageSetupCommand) {
+            return execute((SecStorageSetupCommand)cmd);
+        } else if (cmd instanceof ComputeChecksumCommand) {
+            return execute((ComputeChecksumCommand)cmd);
+        } else if (cmd instanceof ListTemplateCommand) {
+            return execute((ListTemplateCommand)cmd);
+        } else if (cmd instanceof ListVolumeCommand) {
+            return execute((ListVolumeCommand)cmd);
+        } else if (cmd instanceof DeleteSnapshotsDirCommand) {
+            return execute((DeleteSnapshotsDirCommand)cmd);
+        } else if (cmd instanceof CopyCommand) {
+            return execute((CopyCommand)cmd);
+        } else if (cmd instanceof DeleteCommand) {
+            return execute((DeleteCommand)cmd);
+        } else {
+            return Answer.createUnsupportedCommandAnswer(cmd);
+        }
+    }
+
+    protected CopyCmdAnswer postProcessing(File destFile, String downloadPath, String destPath, DataTO srcData, DataTO destData) throws ConfigurationException {
+        if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
+            SnapshotObjectTO snapshot = new SnapshotObjectTO();
+            snapshot.setPath(destPath + File.separator + destFile.getName());
+
+            CopyCmdAnswer answer = new CopyCmdAnswer(snapshot);
+            return answer;
+        }
+        // do post processing to unzip the file if it is compressed
+        String scriptsDir = "scripts/storage/secondary";
+        String createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
+        if (createTmpltScr == null) {
+            throw new ConfigurationException("Unable to find createtmplt.sh");
+        }
+        s_logger.info("createtmplt.sh found in " + createTmpltScr);
+        String createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
+        if (createVolScr == null) {
+            throw new ConfigurationException("Unable to find createvolume.sh");
+        }
+        s_logger.info("createvolume.sh found in " + createVolScr);
+        String script = srcData.getObjectType() == DataObjectType.TEMPLATE ? createTmpltScr : createVolScr;
+
+        int installTimeoutPerGig = 180 * 60 * 1000;
+        long imgSizeGigs = (long)Math.ceil(destFile.length() * 1.0d / (1024 * 1024 * 1024));
+        imgSizeGigs++; // add one just in case
+        long timeout = imgSizeGigs * installTimeoutPerGig;
+
+        String origPath = destFile.getAbsolutePath();
+        String extension = null;
+        if (srcData.getObjectType() == DataObjectType.TEMPLATE) {
+            extension = ((TemplateObjectTO)srcData).getFormat().getFileExtension();
+        } else if (srcData.getObjectType() == DataObjectType.VOLUME) {
+            extension = ((VolumeObjectTO)srcData).getFormat().getFileExtension();
+        }
+
+        String templateName = UUID.randomUUID().toString();
+        String templateFilename = templateName + "." + extension;
+        Script scr = new Script(script, timeout, s_logger);
+        scr.add("-s", Long.toString(imgSizeGigs)); // not used for now
+        scr.add("-n", templateFilename);
+
+        scr.add("-t", downloadPath);
+        scr.add("-f", origPath); // this is the temporary
+        // template file downloaded
+        String result;
+        result = scr.execute();
+
+        if (result != null) {
+            // script execution failure
+            throw new CloudRuntimeException("Failed to run script " + script);
+        }
+
+        String finalFileName = templateFilename;
+        String finalDownloadPath = destPath + File.separator + templateFilename;
+        // compute the size of
+        long size = _storage.getSize(downloadPath + File.separator + templateFilename);
+
+        DataTO newDestTO = null;
+
+        if (destData.getObjectType() == DataObjectType.TEMPLATE) {
+            TemplateObjectTO newTemplTO = new TemplateObjectTO();
+            newTemplTO.setPath(finalDownloadPath);
+            newTemplTO.setName(finalFileName);
+            newTemplTO.setSize(size);
+            newTemplTO.setPhysicalSize(size);
+            newDestTO = newTemplTO;
+        } else {
+            VolumeObjectTO newVolTO = new VolumeObjectTO();
+            newVolTO.setPath(finalDownloadPath);
+            newVolTO.setName(finalFileName);
+            newVolTO.setSize(size);
+            newDestTO = newVolTO;
+        }
+
+        return new CopyCmdAnswer(newDestTO);
+    }
+
+    protected Answer copyFromSwiftToNfs(CopyCommand cmd, DataTO srcData, SwiftTO swiftTO, DataTO destData, NfsTO destImageStore) {
+        final String storagePath = destImageStore.getUrl();
+        final String destPath = destData.getPath();
+        try {
+            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
+            final File downloadDirectory = _storage.getFile(downloadPath);
+            if (!downloadDirectory.mkdirs()) {
+                return new CopyCmdAnswer("Failed to create download directory " + downloadPath);
+            }
+            File destFile = SwiftUtil.getObject(swiftTO, downloadDirectory, srcData.getPath());
+            return postProcessing(destFile, downloadPath, destPath, srcData, destData);
+        } catch (Exception e) {
+            s_logger.debug("Failed to copy swift to nfs", e);
+            return new CopyCmdAnswer(e.toString());
+        }
+    }
+
+    protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataTO destData, NfsTO destImageStore) {
+        final String storagePath = destImageStore.getUrl();
+        final String destPath = destData.getPath();
+
+        try {
+
+            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
+            final File downloadDirectory = _storage.getFile(downloadPath);
+
+            if (!downloadDirectory.mkdirs()) {
+                final String errMsg = "Unable to create directory " + downloadPath + " to copy from S3 to cache.";
+                s_logger.error(errMsg);
+                return new CopyCmdAnswer(errMsg);
+            } else {
+                s_logger.debug("Directory " + downloadPath + " already exists");
+            }
+
+            File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory, new FileNamingStrategy() {
+                @Override
+                public String determineFileName(final String key) {
+                    return substringAfterLast(key, S3Utils.SEPARATOR);
+                }
+            });
+
+            if (destFile == null) {
+                return new CopyCmdAnswer("Can't find template");
+            }
+
+            return postProcessing(destFile, downloadPath, destPath, srcData, destData);
+        } catch (Exception e) {
+
+            final String errMsg = format("Failed to download" + "due to $2%s", e.getMessage());
+            s_logger.error(errMsg, e);
+            return new CopyCmdAnswer(errMsg);
+        }
+    }
+
+    protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData,
+            NfsTO destDataStore) {
+        String srcMountPoint = getRootDir(srcDataStore.getUrl());
+        String snapshotPath = srcData.getPath();
+        int index = snapshotPath.lastIndexOf("/");
+        String snapshotName = snapshotPath.substring(index + 1);
+        if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
+            snapshotName = snapshotName + ".vhd";
+        }
+        snapshotPath = snapshotPath.substring(0, index);
+
+        snapshotPath = srcMountPoint + File.separator + snapshotPath;
+        String destMountPoint = getRootDir(destDataStore.getUrl());
+        String destPath = destMountPoint + File.separator + destData.getPath();
+
+        String errMsg = null;
+        try {
+            _storage.mkdir(destPath);
+
+            String templateUuid = UUID.randomUUID().toString();
+            String templateName = templateUuid + ".vhd";
+            Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
+            command.add("-p", snapshotPath);
+            command.add("-s", snapshotName);
+            command.add("-n", templateName);
+            command.add("-t", destPath);
+            String result = command.execute();
+
+            if (result != null && !result.equalsIgnoreCase("")) {
+                return new CopyCmdAnswer(result);
+            }
+
+            Map<String, Object> params = new HashMap<String, Object>();
+            params.put(StorageLayer.InstanceConfigKey, _storage);
+            Processor processor = new VhdProcessor();
+
+            processor.configure("Vhd Processor", params);
+            FormatInfo info = processor.process(destPath, null, templateUuid);
+
+            TemplateLocation loc = new TemplateLocation(_storage, destPath);
+            loc.create(1, true, templateUuid);
+            loc.addFormat(info);
+            loc.save();
+            TemplateProp prop = loc.getTemplateInfo();
+            TemplateObjectTO newTemplate = new TemplateObjectTO();
+            newTemplate.setPath(destData.getPath() + File.separator + templateName);
+            newTemplate.setFormat(ImageFormat.VHD);
+            newTemplate.setSize(prop.getSize());
+            newTemplate.setPhysicalSize(prop.getPhysicalSize());
+            newTemplate.setName(templateUuid);
+            return new CopyCmdAnswer(newTemplate);
+        } catch (ConfigurationException e) {
+            s_logger.debug("Failed to create template from snapshot: " + e.toString());
+            errMsg = e.toString();
+        } catch (InternalErrorException e) {
+            s_logger.debug("Failed to create template from snapshot: " + e.toString());
+            errMsg = e.toString();
+        } catch (IOException e) {
+            s_logger.debug("Failed to create template from snapshot: " + e.toString());
+            errMsg = e.toString();
+        }
+
+        return new CopyCmdAnswer(errMsg);
+    }
+
+    protected Answer copySnapshotToTemplateFromNfsToNfs(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
+
+        if (srcData.getHypervisorType() == HypervisorType.XenServer) {
+            return copySnapshotToTemplateFromNfsToNfsXenserver(cmd, srcData, srcDataStore, destData, destDataStore);
+        } else if (srcData.getHypervisorType() == HypervisorType.KVM) {
+            File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl());
+            File destFile = getFile(destData.getPath(), destDataStore.getUrl());
+
+            VolumeObjectTO volumeObjectTO = srcData.getVolume();
+            ImageFormat srcFormat = null;
+            //TODO: the image format should be stored in snapshot table, instead of getting from volume
+            if (volumeObjectTO != null) {
+                srcFormat = volumeObjectTO.getFormat();
+            } else {
+                srcFormat = ImageFormat.QCOW2;
+            }
+
+            // get snapshot file name
+            String templateName = srcFile.getName();
+            // add kvm file extension for copied template name
+            String fileName = templateName + "." + srcFormat.getFileExtension();
+            String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName;
+            s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath);
+            Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
+            try {
+                // generate template.properties file
+                String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
+                _storage.create(destFile.getAbsolutePath(), "template.properties");
+                File metaFile = new File(metaFileName);
+                FileWriter writer = new FileWriter(metaFile);
+                BufferedWriter bufferWriter = new BufferedWriter(writer);
+                // KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need
+                // to send template name back.
+                bufferWriter.write("uniquename=" + destData.getName());
+                bufferWriter.write("\n");
+                bufferWriter.write("filename=" + fileName);
+                bufferWriter.write("\n");
+                long size = _storage.getSize(destFileFullPath);
+                bufferWriter.write("size=" + size);
+                bufferWriter.close();
+                writer.close();
+
+                /**
+                 * Snapshots might be in either QCOW2 or RAW image format
+                 *
+                 * For example RBD snapshots are in RAW format
+                 */
+                Processor processor = null;
+                if (srcFormat == ImageFormat.QCOW2) {
+                    processor = new QCOW2Processor();
+                } else if (srcFormat == ImageFormat.RAW) {
+                    processor = new RawImageProcessor();
+                } else {
+                    throw new ConfigurationException("Unknown image format " + srcFormat.toString());
+                }
+
+                Map<String, Object> params = new HashMap<String, Object>();
+                params.put(StorageLayer.InstanceConfigKey, _storage);
+
+                processor.configure("template processor", params);
+                String destPath = destFile.getAbsolutePath();
+
+                FormatInfo info = processor.process(destPath, null, templateName);
+                TemplateLocation loc = new TemplateLocation(_storage, destPath);
+                loc.create(1, true, destData.getName());
+                loc.addFormat(info);
+                loc.save();
+
+                TemplateProp prop = loc.getTemplateInfo();
+                TemplateObjectTO newTemplate = new TemplateObjectTO();
+                newTemplate.setPath(destData.getPath() + File.separator + fileName);
+                newTemplate.setFormat(srcFormat);
+                newTemplate.setSize(prop.getSize());
+                newTemplate.setPhysicalSize(prop.getPhysicalSize());
+                return new CopyCmdAnswer(newTemplate);
+            } catch (ConfigurationException e) {
+                s_logger.debug("Failed to create template:" + e.toString());
+                return new CopyCmdAnswer(e.toString());
+            } catch (IOException e) {
+                s_logger.debug("Failed to create template:" + e.toString());
+                return new CopyCmdAnswer(e.toString());
+            } catch (InternalErrorException e) {
+                s_logger.debug("Failed to create template:" + e.toString());
+                return new CopyCmdAnswer(e.toString());
+            }
+        }
+
+        return new CopyCmdAnswer("");
+    }
+
+    protected File getFile(String path, String nfsPath) {
+        String filePath = getRootDir(nfsPath) + File.separator + path;
+        File f = new File(filePath);
+        if (!f.exists()) {
+            _storage.mkdirs(filePath);
+            f = new File(filePath);
+        }
+        return f;
+    }
+
+    protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
+        DataTO srcData = cmd.getSrcTO();
+        DataTO destData = cmd.getDestTO();
+        DataStoreTO srcDataStore = srcData.getDataStore();
+        DataStoreTO destDataStore = destData.getDataStore();
+        if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
+            if (!(srcDataStore instanceof NfsTO)) {
+                s_logger.debug("only support nfs storage as src, when create template from snapshot");
+                return Answer.createUnsupportedCommandAnswer(cmd);
+            }
+
+            if (destDataStore instanceof NfsTO) {
+                return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData, (NfsTO)destDataStore);
+            } else if (destDataStore instanceof SwiftTO) {
+                //create template on the same data store
+                CopyCmdAnswer answer =
+                        (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData,
+                                (NfsTO)srcDataStore);
+                if (!answer.getResult()) {
+                    return answer;
+                }
+                s_logger.debug("starting copy template to swift");
+                DataTO newTemplate = answer.getNewData();
+                File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl());
+                SwiftTO swift = (SwiftTO)destDataStore;
+                String containterName = SwiftUtil.getContainerName(destData.getObjectType().toString(), destData.getId());
+                String swiftPath = SwiftUtil.putObject(swift, templateFile, containterName, templateFile.getName());
+                //upload template.properties
+                File properties = new File(templateFile.getParent() + File.separator + _tmpltpp);
+                if (properties.exists()) {
+                    SwiftUtil.putObject(swift, properties, containterName, _tmpltpp);
+                }
+
+                //clean up template data on staging area
+                try {
+                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
+                    execute(deleteCommand);
+                } catch (Exception e) {
+                    s_logger.debug("Failed to clean up staging area:", e);
+                }
+
+                TemplateObjectTO template = new TemplateObjectTO();
+                template.setPath(swiftPath);
+                template.setSize(templateFile.length());
+                template.setPhysicalSize(template.getSize());
+                SnapshotObjectTO snapshot = (SnapshotObjectTO)srcData;
+                template.setFormat(snapshot.getVolume().getFormat());
+                return new CopyCmdAnswer(template);
+            } else if (destDataStore instanceof S3TO) {
+                //create template on the same data store
+                CopyCmdAnswer answer =
+                        (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData,
+                                (NfsTO)srcDataStore);
+                if (!answer.getResult()) {
+                    return answer;
+                }
+                TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData();
+                newTemplate.setDataStore(srcDataStore);
+                CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
+                Answer result = copyFromNfsToS3(newCpyCmd);
+                //clean up template data on staging area
+                try {
+                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
+                    execute(deleteCommand);
+                } catch (Exception e) {
+                    s_logger.debug("Failed to clean up staging area:", e);
+                }
+                return result;
+            }
+        }
+        s_logger.debug("Failed to create templat from snapshot");
+        return new CopyCmdAnswer("Unsupported prototcol");
+    }
+
+    protected Answer copyFromNfsToImage(CopyCommand cmd) {
+        DataTO destData = cmd.getDestTO();
+        DataStoreTO destDataStore = destData.getDataStore();
+
+        if (destDataStore instanceof S3TO) {
+            return copyFromNfsToS3(cmd);
+        } else {
+            return new CopyCmdAnswer("unsupported ");
+        }
+    }
+
+    protected Answer execute(CopyCommand cmd) {
+        DataTO srcData = cmd.getSrcTO();
+        DataTO destData = cmd.getDestTO();
+        DataStoreTO srcDataStore = srcData.getDataStore();
+        DataStoreTO destDataStore = destData.getDataStore();
+
+        if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
+            return createTemplateFromSnapshot(cmd);
+        }
+
+        if (destDataStore instanceof NfsTO && destDataStore.getRole() == DataStoreRole.ImageCache) {
+            NfsTO destImageStore = (NfsTO)destDataStore;
+            if (srcDataStore instanceof S3TO) {
+                S3TO s3 = (S3TO)srcDataStore;
+                return copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore);
+            } else if (srcDataStore instanceof SwiftTO) {
+                return copyFromSwiftToNfs(cmd, srcData, (SwiftTO)srcDataStore, destData, destImageStore);
+            }
+        }
+
+        if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
+            return copyFromNfsToImage(cmd);
+        }
+
+        return Answer.createUnsupportedCommandAnswer(cmd);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected String determineS3TemplateDirectory(final Long accountId, final Long templateId, final String templateUniqueName) {
+        return join(asList(TEMPLATE_ROOT_DIR, accountId, templateId, templateUniqueName), S3Utils.SEPARATOR);
+    }
+
+    private String determineS3TemplateNameFromKey(String key) {
+        return StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected String determineS3VolumeDirectory(final Long accountId, final Long volId) {
+        return join(asList(VOLUME_ROOT_DIR, accountId, volId), S3Utils.SEPARATOR);
+    }
+
+    protected Long determineS3VolumeIdFromKey(String key) {
+        return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR));
+    }
+
+    private String determineStorageTemplatePath(final String storagePath, String dataPath) {
+        return join(asList(getRootDir(storagePath), dataPath), File.separator);
+    }
+
+    protected File downloadFromUrlToNfs(String url, NfsTO nfs, String path, String name) {
+        HttpClient client = new DefaultHttpClient();
+        HttpGet get = new HttpGet(url);
+        try {
+            HttpResponse response = client.execute(get);
+            HttpEntity entity = response.getEntity();
+            if (entity == null) {
+                s_logger.debug("Faled to get entity");
+                throw new CloudRuntimeException("Failed to get url: " + url);
+            }
+
+            String nfsMountPath = getRootDir(nfs.getUrl());
+
+            String filePath = nfsMountPath + File.separator + path;
+            File directory = new File(filePath);
+            if (!directory.exists()) {
+                _storage.mkdirs(filePath);
+            }
+            File destFile = new File(filePath + File.separator + name);
+            if (!destFile.createNewFile()) {
+                s_logger.warn("Reusing existing file " + destFile.getPath());
+            }
+            FileOutputStream outputStream = new FileOutputStream(destFile);
+            entity.writeTo(outputStream);
+            return new File(destFile.getAbsolutePath());
+        } catch (IOException e) {
+            s_logger.debug("Faild to get url:" + url + ", due to " + e.toString());
+            throw new CloudRuntimeException(e);
+        }
+    }
+
+    protected Answer registerTemplateOnSwift(DownloadCommand cmd) {
+        SwiftTO swiftTO = (SwiftTO)cmd.getDataStore();
+        String path = cmd.getInstallPath();
+        DataStoreTO cacheStore = cmd.getCacheStore();
+        if (cacheStore == null || !(cacheStore instanceof NfsTO)) {
+            return new DownloadAnswer("cache store can't be null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
+        }
+
+        File file = null;
+        try {
+            NfsTO nfsCacheStore = (NfsTO)cacheStore;
+            String fileName = cmd.getName() + "." + cmd.getFormat().getFileExtension();
+            file = downloadFromUrlToNfs(cmd.getUrl(), nfsCacheStore, path, fileName);
+            String container = "T-" + cmd.getId();
+            String swiftPath = SwiftUtil.putObject(swiftTO, file, container, null);
+
+            //put metda file
+            File uniqDir = _storage.createUniqDir();
+            String metaFileName = uniqDir.getAbsolutePath() + File.separator + "template.properties";
+            _storage.create(uniqDir.getAbsolutePath(), "template.properties");
+            File metaFile = new File(metaFileName);
+            FileWriter writer = new FileWriter(metaFile);
+            BufferedWriter bufferWriter = new BufferedWriter(writer);
+            bufferWriter.write("uniquename=" + cmd.getName());
+            bufferWriter.write("\n");
+            bufferWriter.write("filename=" + fileName);
+            bufferWriter.write("\n");
+            bufferWriter.write("size=" + file.length());
+            bufferWriter.close();
+            writer.close();
+
+            SwiftUtil.putObject(swiftTO, metaFile, container, "template.properties");
+            metaFile.delete();
+            uniqDir.delete();
+            String md5sum = null;
+            try {
+                md5sum = DigestUtils.md5Hex(new FileInputStream(file));
+            } catch (IOException e) {
+                s_logger.debug("Failed to get md5sum: " + file.getAbsoluteFile());
+            }
+
+            DownloadAnswer answer =
+                    new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, swiftPath, swiftPath, file.length(), file.length(), md5sum);
+            return answer;
+        } catch (IOException e) {
+            s_logger.debug("Failed to register template into swift", e);
+            return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
+        } finally {
+            if (file != null) {
+                file.delete();
+            }
+        }
+    }
+
+    private Answer execute(DownloadCommand cmd) {
+        DataStoreTO dstore = cmd.getDataStore();
+        if (dstore instanceof NfsTO || dstore instanceof S3TO) {
+            return _dlMgr.handleDownloadCommand(this, cmd);
+        } else if (dstore instanceof SwiftTO) {
+            return registerTemplateOnSwift(cmd);
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
+        }
+
+    }
+
+    private ImageFormat getTemplateFormat(String filePath) {
+        String ext = null;
+        int extensionPos = filePath.lastIndexOf('.');
+        int lastSeparator = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
+        int i = lastSeparator > extensionPos ? -1 : extensionPos;
+        if (i > 0) {
+            ext = filePath.substring(i + 1);
+        }
+        if (ext != null) {
+            if (ext.equalsIgnoreCase("vhd")) {
+                return ImageFormat.VHD;
+            } else if (ext.equalsIgnoreCase("vhdx")) {
+                return ImageFormat.VHDX;
+            } else if (ext.equalsIgnoreCase("qcow2")) {
+                return ImageFormat.QCOW2;
+            } else if (ext.equalsIgnoreCase("ova")) {
+                return ImageFormat.OVA;
+            } else if (ext.equalsIgnoreCase("tar")) {
+                return ImageFormat.TAR;
+            } else if (ext.equalsIgnoreCase("img") || ext.equalsIgnoreCase("raw")) {
+                return ImageFormat.RAW;
+            } else if (ext.equalsIgnoreCase("vmdk")) {
+                return ImageFormat.VMDK;
+            } else if (ext.equalsIgnoreCase("vdi")) {
+                return ImageFormat.VDI;
+            }
+        }
+
+        return null;
+
+    }
+
+    protected Long getVirtualSize(File file, ImageFormat format) {
+        Processor processor = null;
+        try {
+            if (format == null) {
+                return file.length();
+            } else if (format == ImageFormat.QCOW2) {
+                processor = new QCOW2Processor();
+            } else if (format == ImageFormat.OVA) {
+                processor = new OVAProcessor();
+            } else if (format == ImageFormat.VHD) {
+                processor = new VhdProcessor();
+            } else if (format == ImageFormat.RAW) {
+                processor = new RawImageProcessor();
+            } else if (format == ImageFormat.VMDK) {
+                processor = new VmdkProcessor();
+            }
+
+            if (processor == null) {
+                return file.length();
+            }
+
+            processor.configure("template processor", new HashMap<String, Object>());
+            return processor.getVirtualSize(file);
+        } catch (Exception e) {
+            s_logger.debug("Failed to get virtual size:", e);
+        }
+        return file.length();
+    }
+
+    protected Answer copyFromNfsToS3(CopyCommand cmd) {
+        final DataTO srcData = cmd.getSrcTO();
+        final DataTO destData = cmd.getDestTO();
+        DataStoreTO srcDataStore = srcData.getDataStore();
+        NfsTO srcStore = (NfsTO)srcDataStore;
+        DataStoreTO destDataStore = destData.getDataStore();
+
+        final S3TO s3 = (S3TO)destDataStore;
+
+        try {
+            final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath());
+
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
+            }
+
+            final String bucket = s3.getBucketName();
+            File srcFile = _storage.getFile(templatePath);
+            // guard the case where templatePath does not have file extension, since we are not completely sure
+            // about hypervisor, so we check each extension
+            if (!srcFile.exists()) {
+                srcFile = _storage.getFile(templatePath + ".qcow2");
+                if (!srcFile.exists()) {
+                    srcFile = _storage.getFile(templatePath + ".vhd");
+                    if (!srcFile.exists()) {
+                        srcFile = _storage.getFile(templatePath + ".ova");
+                        if (!srcFile.exists()) {
+                            srcFile = _storage.getFile(templatePath + ".vmdk");
+                            if (!srcFile.exists()) {
+                                return new CopyCmdAnswer("Can't find src file:" + templatePath);
+                            }
+                        }
+                    }
+                }
+            }
+
+            long srcSize = srcFile.length();
+            ImageFormat format = getTemplateFormat(srcFile.getName());
+            String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
+            if (!s3.getSingleUpload(srcSize)) {
+                mputFile(s3, srcFile, bucket, key);
+            } else {
+                putFile(s3, srcFile, bucket, key);
+            }
+
+            DataTO retObj = null;
+            if (destData.getObjectType() == DataObjectType.TEMPLATE) {
+                TemplateObjectTO newTemplate = new TemplateObjectTO();
+                newTemplate.setPath(key);
+                newTemplate.setSize(getVirtualSize(srcFile, format));
+                newTemplate.setPhysicalSize(srcFile.length());
+                newTemplate.setFormat(format);
+                retObj = newTemplate;
+            } else if (destData.getObjectType() == DataObjectType.VOLUME) {
+                VolumeObjectTO newVol = new VolumeObjectTO();
+                newVol.setPath(key);
+                newVol.setSize(srcFile.length());
+                retObj = newVol;
+            } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
+                SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
+                newSnapshot.setPath(key);
+                retObj = newSnapshot;
+            }
+
+            return new CopyCmdAnswer(retObj);
+        } catch (Exception e) {
+            s_logger.error("failed to upload" + srcData.getPath(), e);
+            return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
+        }
+    }
+
+    String swiftDownload(SwiftTO swift, String container, String rfilename, String lFullPath) {
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
+                swift.getUserName() + " -K " + swift.getKey() + " download " + container + " " + rfilename + " -o " + lFullPath);
+        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+        String result = command.execute(parser);
+        if (result != null) {
+            String errMsg = "swiftDownload failed  err=" + result;
+            s_logger.warn(errMsg);
+            return errMsg;
+        }
+        if (parser.getLines() != null) {
+            String[] lines = parser.getLines().split("\\n");
+            for (String line : lines) {
+                if (line.contains("Errno") || line.contains("failed")) {
+                    String errMsg = "swiftDownload failed , err=" + parser.getLines();
+                    s_logger.warn(errMsg);
+                    return errMsg;
+                }
+            }
+        }
+        return null;
+
+    }
+
+    String swiftDownloadContainer(SwiftTO swift, String container, String ldir) {
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("cd " + ldir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
+                swift.getUserName() + " -K " + swift.getKey() + " download " + container);
+        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+        String result = command.execute(parser);
+        if (result != null) {
+            String errMsg = "swiftDownloadContainer failed  err=" + result;
+            s_logger.warn(errMsg);
+            return errMsg;
+        }
+        if (parser.getLines() != null) {
+            String[] lines = parser.getLines().split("\\n");
+            for (String line : lines) {
+                if (line.contains("Errno") || line.contains("failed")) {
+                    String errMsg = "swiftDownloadContainer failed , err=" + parser.getLines();
+                    s_logger.warn(errMsg);
+                    return errMsg;
+                }
+            }
+        }
+        return null;
+
+    }
+
+    String swiftUpload(SwiftTO swift, String container, String lDir, String lFilename) {
+        long SWIFT_MAX_SIZE = 5L * 1024L * 1024L * 1024L;
+        List<String> files = new ArrayList<String>();
+        if (lFilename.equals("*")) {
+            File dir = new File(lDir);
+            for (String file : dir.list()) {
+                if (file.startsWith(".")) {
+                    continue;
+                }
+                files.add(file);
+            }
+        } else {
+            files.add(lFilename);
+        }
+
+        for (String file : files) {
+            File f = new File(lDir + "/" + file);
+            long size = f.length();
+            Script command = new Script("/bin/bash", s_logger);
+            command.add("-c");
+            if (size <= SWIFT_MAX_SIZE) {
+                command.add("cd " + lDir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " +
+                        swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " upload " + container + " " + file);
+            } else {
+                command.add("cd " + lDir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " +
+                        swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " upload -S " + SWIFT_MAX_SIZE + " " + container + " " + file);
+            }
+            OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+            String result = command.execute(parser);
+            if (result != null) {
+                String errMsg = "swiftUpload failed , err=" + result;
+                s_logger.warn(errMsg);
+                return errMsg;
+            }
+            if (parser.getLines() != null) {
+                String[] lines = parser.getLines().split("\\n");
+                for (String line : lines) {
+                    if (line.contains("Errno") || line.contains("failed")) {
+                        String errMsg = "swiftUpload failed , err=" + parser.getLines();
+                        s_logger.warn(errMsg);
+                        return errMsg;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    String[] swiftList(SwiftTO swift, String container, String rFilename) {
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
+                swift.getUserName() + " -K " + swift.getKey() + " list " + container + " " + rFilename);
+        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+        String result = command.execute(parser);
+        if (result == null && parser.getLines() != null) {
+            String[] lines = parser.getLines().split("\\n");
+            return lines;
+        } else {
+            if (result != null) {
+                String errMsg = "swiftList failed , err=" + result;
+                s_logger.warn(errMsg);
+            } else {
+                String errMsg = "swiftList failed, no lines returns";
+                s_logger.warn(errMsg);
+            }
+        }
+        return null;
+    }
+
+    String swiftDelete(SwiftTO swift, String container, String object) {
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
+                swift.getUserName() + " -K " + swift.getKey() + " delete " + container + " " + object);
+        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+        String result = command.execute(parser);
+        if (result != null) {
+            String errMsg = "swiftDelete failed , err=" + result;
+            s_logger.warn(errMsg);
+            return errMsg;
+        }
+        if (parser.getLines() != null) {
+            String[] lines = parser.getLines().split("\\n");
+            for (String line : lines) {
+                if (line.contains("Errno") || line.contains("failed")) {
+                    String errMsg = "swiftDelete failed , err=" + parser.getLines();
+                    s_logger.warn(errMsg);
+                    return errMsg;
+                }
+            }
+        }
+        return null;
+    }
+
+    public Answer execute(DeleteSnapshotsDirCommand cmd) {
+        DataStoreTO dstore = cmd.getDataStore();
+        if (dstore instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)dstore;
+            String relativeSnapshotPath = cmd.getDirectory();
+            String parent = getRootDir(nfs.getUrl());
+
+            if (relativeSnapshotPath.startsWith(File.separator)) {
+                relativeSnapshotPath = relativeSnapshotPath.substring(1);
+            }
+
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
+            String absoluteSnapshotPath = parent + relativeSnapshotPath;
+            File snapshotDir = new File(absoluteSnapshotPath);
+            String details = null;
+            if (!snapshotDir.exists()) {
+                details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
+                s_logger.debug(details);
+                return new Answer(cmd, true, details);
+            }
+            // delete all files in the directory
+            String lPath = absoluteSnapshotPath + "/*";
+            String result = deleteLocalFile(lPath);
+            if (result != null) {
+                String errMsg = "failed to delete all snapshots " + lPath + " , err=" + result;
+                s_logger.warn(errMsg);
+                return new Answer(cmd, false, errMsg);
+            }
+            // delete the directory
+            if (!snapshotDir.delete()) {
+                details = "Unable to delete directory " + snapshotDir.getName() + " under snapshot path " + relativeSnapshotPath;
+                s_logger.debug(details);
+                return new Answer(cmd, false, details);
+            }
+            return new Answer(cmd, true, null);
+        } else if (dstore instanceof S3TO) {
+            final S3TO s3 = (S3TO)dstore;
+            final String path = cmd.getDirectory();
+            final String bucket = s3.getBucketName();
+            try {
+                S3Utils.deleteDirectory(s3, bucket, path);
+                return new Answer(cmd, true, String.format("Deleted snapshot %1%s from bucket %2$s.", path, bucket));
+            } catch (Exception e) {
+                final String errorMessage =
+                        String.format("Failed to delete snapshot %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
+                s_logger.error(errorMessage, e);
+                return new Answer(cmd, false, errorMessage);
+            }
+        } else if (dstore instanceof SwiftTO) {
+            String path = cmd.getDirectory();
+            String volumeId = StringUtils.substringAfterLast(path, "/"); // assuming
+            // that
+            // the
+            // filename
+            // is
+            // the
+            // last
+            // section
+            // in
+            // the
+            // path
+            String result = swiftDelete((SwiftTO)dstore, "V-" + volumeId.toString(), "");
+            if (result != null) {
+                String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result;
+                s_logger.warn(errMsg);
+                return new Answer(cmd, false, errMsg);
+            }
+            return new Answer(cmd, true, "Deleted snapshot " + path + " from swift");
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
+        }
+    }
+
+    private Answer execute(ComputeChecksumCommand cmd) {
+
+        String relativeTemplatePath = cmd.getTemplatePath();
+        DataStoreTO store = cmd.getStore();
+        if (!(store instanceof NfsTO)) {
+            return new Answer(cmd, false, "can't handle non nfs data store");
+        }
+        NfsTO nfsStore = (NfsTO)store;
+        String parent = getRootDir(nfsStore.getUrl());
+
+        if (relativeTemplatePath.startsWith(File.separator)) {
+            relativeTemplatePath = relativeTemplatePath.substring(1);
+        }
+
+        if (!parent.endsWith(File.separator)) {
+            parent += File.separator;
+        }
+        String absoluteTemplatePath = parent + relativeTemplatePath;
+        MessageDigest digest;
+        String checksum = null;
+        File f = new File(absoluteTemplatePath);
+        InputStream is = null;
+        byte[] buffer = new byte[8192];
+        int read = 0;
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("parent path " + parent + " relative template path " + relativeTemplatePath);
+        }
+
+        try {
+            digest = MessageDigest.getInstance("MD5");
+            is = new FileInputStream(f);
+            while ((read = is.read(buffer)) > 0) {
+                digest.update(buffer, 0, read);
+            }
+            byte[] md5sum = digest.digest();
+            BigInteger bigInt = new BigInteger(1, md5sum);
+            checksum = bigInt.toString(16);
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Successfully calculated checksum for file " + absoluteTemplatePath + " - " + checksum);
+            }
+
+        } catch (IOException e) {
+            String logMsg = "Unable to process file for MD5 - " + absoluteTemplatePath;
+            s_logger.error(logMsg);
+            return new Answer(cmd, false, checksum);
+        } catch (NoSuchAlgorithmException e) {
+            return new Answer(cmd, false, checksum);
+        } finally {
+            try {
+                if (is != null) {
+                    is.close();
+                }
+            } catch (IOException e) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Could not close the file " + absoluteTemplatePath);
+                }
+                return new Answer(cmd, false, checksum);
+            }
+        }
+
+        return new Answer(cmd, true, checksum);
+    }
+
+    private void configCerts(KeystoreManager.Certificates certs) {
+        if (certs == null) {
+            configureSSL();
+        } else {
+            String prvKey = certs.getPrivKey();
+            String pubCert = certs.getPrivCert();
+
+            try {
+                File prvKeyFile = File.createTempFile("prvkey", null);
+                String prvkeyPath = prvKeyFile.getAbsolutePath();
+                BufferedWriter out = new BufferedWriter(new FileWriter(prvKeyFile));
+                out.write(prvKey);
+                out.close();
+
+                File pubCertFile = File.createTempFile("pubcert", null);
+                String pubCertFilePath = pubCertFile.getAbsolutePath();
+
+                out = new BufferedWriter(new FileWriter(pubCertFile));
+                out.write(pubCert);
+                out.close();
+
+                configureSSL(prvkeyPath, pubCertFilePath, null);
+
+                prvKeyFile.delete();
+                pubCertFile.delete();
+
+            } catch (IOException e) {
+                s_logger.debug("Failed to config ssl: " + e.toString());
+            }
+        }
+    }
+
+    private Answer execute(SecStorageSetupCommand cmd) {
+        if (!_inSystemVM) {
+            return new Answer(cmd, true, null);
+        }
+        DataStoreTO dStore = cmd.getDataStore();
+        if (dStore instanceof NfsTO) {
+            String secUrl = cmd.getSecUrl();
+            try {
+                URI uri = new URI(secUrl);
+                String nfsHostIp = getUriHostIp(uri);
+
+                addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
+                String dir = mountUri(uri);
+
+                configCerts(cmd.getCerts());
+
+                nfsIps.add(nfsHostIp);
+                return new SecStorageSetupAnswer(dir);
+            } catch (Exception e) {
+                String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
+                s_logger.error(msg);
+                return new Answer(cmd, false, msg);
+
+            }
+        } else {
+            // TODO: what do we need to setup for S3/Swift, maybe need to mount
+            // to some cache storage
+            return new Answer(cmd, true, null);
+        }
+    }
+
+    protected Answer deleteSnapshot(final DeleteCommand cmd) {
+        DataTO obj = cmd.getData();
+        DataStoreTO dstore = obj.getDataStore();
+        if (dstore instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)dstore;
+            String parent = getRootDir(nfs.getUrl());
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
+            String snapshotPath = obj.getPath();
+            if (snapshotPath.startsWith(File.separator)) {
+                snapshotPath = snapshotPath.substring(1);
+            }
+            // check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of
+            // snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing
+            // and return true.
+            String fullSnapPath = parent + snapshotPath;
+            File snapDir = new File(fullSnapPath);
+            if (snapDir.exists() && snapDir.isDirectory()) {
+                s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete");
+                return new Answer(cmd, true, null);
+            }
+            // passed snapshot path is a snapshot file path, then get snapshot directory first
+            int index = snapshotPath.lastIndexOf("/");
+            String snapshotName = snapshotPath.substring(index + 1);
+            snapshotPath = snapshotPath.substring(0, index);
+            String absoluteSnapshotPath = parent + snapshotPath;
+            // check if snapshot directory exists
+            File snapshotDir = new File(absoluteSnapshotPath);
+            String details = null;
+            if (!snapshotDir.exists()) {
+                details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
+                s_logger.debug(details);
+                return new Answer(cmd, false, details);
+            }
+            // delete snapshot in the directory if exists
+            String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
+            String result = deleteLocalFile(lPath);
+            if (result != null) {
+                details = "failed to delete snapshot " + lPath + " , err=" + result;
+                s_logger.warn(details);
+                return new Answer(cmd, false, details);
+            }
+            return new Answer(cmd, true, null);
+        } else if (dstore instanceof S3TO) {
+            final S3TO s3 = (S3TO)dstore;
+            final String path = obj.getPath();
+            final String bucket = s3.getBucketName();
+            try {
+                S3Utils.deleteObject(s3, bucket, path);
+                return new Answer(cmd, true, String.format("Deleted snapshot %1%s from bucket %2$s.", path, bucket));
+            } catch (Exception e) {
+                final String errorMessage =
+                        String.format("Failed to delete snapshot %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
+                s_logger.error(errorMessage, e);
+                return new Answer(cmd, false, errorMessage);
+            }
+        } else if (dstore instanceof SwiftTO) {
+            SwiftTO swiftTO = (SwiftTO)dstore;
+            String path = obj.getPath();
+            SwiftUtil.deleteObject(swiftTO, path);
+
+            return new Answer(cmd, true, "Deleted snapshot " + path + " from swift");
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
+        }
+
+    }
+
+    Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
+        String[] containers = SwiftUtil.list(swift, "", null);
+        if (containers == null) {
+            return null;
+        }
+        Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
+        for (String container : containers) {
+            if (container.startsWith("T-")) {
+                String[] files = SwiftUtil.list(swift, container, "template.properties");
+                if (files.length != 1) {
+                    continue;
+                }
+                try {
+                    File tempFile = File.createTempFile("template", ".tmp");
+                    File tmpFile = SwiftUtil.getObject(swift, tempFile, container + File.separator + "template.properties");
+                    if (tmpFile == null) {
+                        continue;
+                    }
+                    FileReader fr = new FileReader(tmpFile);
+                    BufferedReader brf = new BufferedReader(fr);
+                    String line = null;
+                    String uniqName = null;
+                    Long size = null;
+                    String name = null;
+                    while ((line = brf.readLine()) != null) {
+                        if (line.startsWith("uniquename=")) {
+                            uniqName = line.split("=")[1];
+                        } else if (line.startsWith("size=")) {
+                            size = Long.parseLong(line.split("=")[1]);
+                        } else if (line.startsWith("filename=")) {
+                            name = line.split("=")[1];
+                        }
+                    }
+                    brf.close();
+                    tempFile.delete();
+                    if (uniqName != null) {
+                        TemplateProp prop = new TemplateProp(uniqName, container + File.separator + name, size, size, true, false);
+                        tmpltInfos.put(uniqName, prop);
+                    }
+
+                } catch (IOException e) {
+                    s_logger.debug("Failed to create templ file:" + e.toString());
+                    continue;
+                } catch (Exception e) {
+                    s_logger.debug("Failed to get properties: " + e.toString());
+                    continue;
+                }
+            }
+        }
+        return tmpltInfos;
+
+    }
+
+    Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
+        String bucket = s3.getBucketName();
+        // List the objects in the source directory on S3
+        final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, TEMPLATE_ROOT_DIR);
+        if (objectSummaries == null) {
+            return null;
+        }
+        Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
+        for (S3ObjectSummary objectSummary : objectSummaries) {
+            String key = objectSummary.getKey();
+            // String installPath = StringUtils.substringBeforeLast(key,
+            // S3Utils.SEPARATOR);
+            String uniqueName = determineS3TemplateNameFromKey(key);
+            // TODO: isPublic value, where to get?
+            TemplateProp tInfo = new TemplateProp(uniqueName, key, objectSummary.getSize(), objectSummary.getSize(), true, false);
+            tmpltInfos.put(uniqueName, tInfo);
+        }
+        return tmpltInfos;
+
+    }
+
+    Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
+        String bucket = s3.getBucketName();
+        // List the objects in the source directory on S3
+        final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, VOLUME_ROOT_DIR);
+        if (objectSummaries == null) {
+            return null;
+        }
+        Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
+        for (S3ObjectSummary objectSummary : objectSummaries) {
+            String key = objectSummary.getKey();
+            // String installPath = StringUtils.substringBeforeLast(key,
+            // S3Utils.SEPARATOR);
+            Long id = determineS3VolumeIdFromKey(key);
+            // TODO: how to get volume template name
+            TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false);
+            tmpltInfos.put(id, tInfo);
+        }
+        return tmpltInfos;
+
+    }
+
+    private Answer execute(ListTemplateCommand cmd) {
+        if (!_inSystemVM) {
+            return new ListTemplateAnswer(null, null);
+        }
+
+        DataStoreTO store = cmd.getDataStore();
+        if (store instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)store;
+            String secUrl = nfs.getUrl();
+            String root = getRootDir(secUrl);
+            Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
+            return new ListTemplateAnswer(secUrl, templateInfos);
+        } else if (store instanceof SwiftTO) {
+            SwiftTO swift = (SwiftTO)store;
+            Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
+            return new ListTemplateAnswer(swift.toString(), templateInfos);
+        } else if (store instanceof S3TO) {
+            S3TO s3 = (S3TO)store;
+            Map<String, TemplateProp> templateInfos = s3ListTemplate(s3);
+            return new ListTemplateAnswer(s3.getBucketName(), templateInfos);
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + store);
+        }
+    }
+
+    private Answer execute(ListVolumeCommand cmd) {
+        if (!_inSystemVM) {
+            return new ListVolumeAnswer(cmd.getSecUrl(), null);
+        }
+        DataStoreTO store = cmd.getDataStore();
+        if (store instanceof NfsTO) {
+            String root = getRootDir(cmd.getSecUrl());
+            Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
+            return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
+        } else if (store instanceof S3TO) {
+            S3TO s3 = (S3TO)store;
+            Map<Long, TemplateProp> templateInfos = s3ListVolume(s3);
+            return new ListVolumeAnswer(s3.getBucketName(), templateInfos);
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + store);
+        }
+
+    }
+
+    private Answer execute(SecStorageVMSetupCommand cmd) {
+        if (!_inSystemVM) {
+            return new Answer(cmd, true, null);
+        }
+        boolean success = true;
+        StringBuilder result = new StringBuilder();
+        for (String cidr : cmd.getAllowedInternalSites()) {
+            if (nfsIps.contains(cidr)) {
+                /*
+                 * if the internal download ip is the same with secondary
+                 * storage ip, adding internal sites will flush ip route to nfs
+                 * through storage ip.
+                 */
+                continue;
+            }
+            String tmpresult = allowOutgoingOnPrivate(cidr);
+            if (tmpresult != null) {
+                result.append(", ").append(tmpresult);
+                success = false;
+            }
+        }
+        if (success) {
+            if (cmd.getCopyPassword() != null && cmd.getCopyUserName() != null) {
+                String tmpresult = configureAuth(cmd.getCopyUserName(), cmd.getCopyPassword());
+                if (tmpresult != null) {
+                    result.append("Failed to configure auth for copy ").append(tmpresult);
+                    success = false;
+                }
+            }
+        }
+        return new Answer(cmd, success, result.toString());
+
+    }
+
+    private String deleteLocalFile(String fullPath) {
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("rm -f " + fullPath);
+        String result = command.execute();
+        if (result != null) {
+            String errMsg = "Failed to delete file " + fullPath + ", err=" + result;
+            s_logger.warn(errMsg);
+            return errMsg;
+        }
+        return null;
+    }
+
+    public String allowOutgoingOnPrivate(String destCidr) {
+        if (!_inSystemVM) {
+            return null;
+        }
+        Script command = new Script("/bin/bash", s_logger);
+        String intf = "eth1";
+        command.add("-c");
+        command.add("iptables -I OUTPUT -o " + intf + " -d " + destCidr + " -p tcp -m state --state NEW -m tcp  -j ACCEPT");
+
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in allowing outgoing to " + destCidr + ", err=" + result);
+            return "Error in allowing outgoing to " + destCidr + ", err=" + result;
+        }
+
+        addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, destCidr);
+
+        return null;
+    }
+
+    private Answer execute(SecStorageFirewallCfgCommand cmd) {
+        if (!_inSystemVM) {
+            return new Answer(cmd, true, null);
+        }
+
+        List<String> ipList = new ArrayList<String>();
+
+        for (PortConfig pCfg : cmd.getPortConfigs()) {
+            if (pCfg.isAdd()) {
+                ipList.add(pCfg.getSourceIp());
+            }
+        }
+        boolean success = true;
+        String result;
+        result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
+        if (result != null) {
+            success = false;
+        }
+
+        return new Answer(cmd, success, result);
+    }
+
+    protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
+        DataStoreTO store = cmd.getStore();
+        if (store instanceof S3TO || store instanceof SwiftTO) {
+            long infinity = Integer.MAX_VALUE;
+            return new GetStorageStatsAnswer(cmd, infinity, 0L);
+        }
+
+        String rootDir = getRootDir(((NfsTO)store).getUrl());
+        final long usedSize = getUsedSize(rootDir);
+        final long totalSize = getTotalSize(rootDir);
+        if (usedSize == -1 || totalSize == -1) {
+            return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
+        } else {
+            return new GetStorageStatsAnswer(cmd, totalSize, usedSize);
+        }
+    }
+
+    protected Answer execute(final DeleteCommand cmd) {
+        DataTO obj = cmd.getData();
+        DataObjectType objType = obj.getObjectType();
+        if (obj.getPath() == null) {
+            // account for those fake entries for NFS migration to object store
+            return new Answer(cmd, true, "Object with null install path does not exist on image store , no need to delete");
+        }
+        switch (objType) {
+        case TEMPLATE:
+            return deleteTemplate(cmd);
+        case VOLUME:
+            return deleteVolume(cmd);
+        case SNAPSHOT:
+            return deleteSnapshot(cmd);
+        }
+        return Answer.createUnsupportedCommandAnswer(cmd);
+    }
+
+    protected Answer deleteTemplate(DeleteCommand cmd) {
+        DataTO obj = cmd.getData();
+        DataStoreTO dstore = obj.getDataStore();
+        if (dstore instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)dstore;
+            String relativeTemplatePath = obj.getPath();
+            String parent = getRootDir(nfs.getUrl());
+
+            if (relativeTemplatePath.startsWith(File.separator)) {
+                relativeTemplatePath = relativeTemplatePath.substring(1);
+            }
+
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
+            String absoluteTemplatePath = parent + relativeTemplatePath;
+            File tmpltPath = new File(absoluteTemplatePath);
+            File tmpltParent = null;
+            if(tmpltPath.exists() && tmpltPath.isDirectory()) {
+                tmpltParent = tmpltPath;
+            } else {
+                tmpltParent = tmpltPath.getParentFile();
+            }
+
+            String details = null;
+            if (!tmpltParent.exists()) {
+                details = "template parent directory " + tmpltParent.getName() + " doesn't exist";
+                s_logger.debug(details);
+                return new Answer(cmd, true, details);
+            }
+            File[] tmpltFiles = tmpltParent.listFiles();
+            if (tmpltFiles == null || tmpltFiles.length == 0) {
+                details = "No files under template parent directory " + tmpltParent.getName();
+                s_logger.debug(details);
+            } else {
+                boolean found = false;
+                for (File f : tmpltFiles) {
+                    if (!found && f.getName().equals("template.properties")) {
+                        found = true;
+                    }
+
+                    // KVM HA monitor makes a mess in the templates with its
+                    // heartbeat tests
+                    // Don't let this stop us from cleaning up the template
+                    if (f.isDirectory() && f.getName().equals("KVMHA")) {
+                        s_logger.debug("Deleting KVMHA directory contents from template location");
+                        File[] haFiles = f.listFiles();
+                        for (File haFile : haFiles) {
+                            haFile.delete();
+                        }
+                    }
+
+                    if (!f.delete()) {
+                        return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Template path " + relativeTemplatePath);
+                    }
+                }
+
+                if (!found) {
+                    details = "Can not find template.properties under " + tmpltParent.getName();
+                    s_logger.debug(details);
+                }
+            }
+            if (!tmpltParent.delete()) {
+                details = "Unable to delete directory " + tmpltParent.getName() + " under Template path " + relativeTemplatePath;
+                s_logger.debug(details);
+                return new Answer(cmd, false, details);
+            }
+            return new Answer(cmd, true, null);
+        } else if (dstore instanceof S3TO) {
+            final S3TO s3 = (S3TO)dstore;
+            final String path = obj.getPath();
+            final String bucket = s3.getBucketName();
+            try {
+                S3Utils.deleteDirectory(s3, bucket, path);
+                return new Answer(cmd, true, String.format("Deleted template %1$s from bucket %2$s.", path, bucket));
+            } catch (Exception e) {
+                final String errorMessage =
+                        String.format("Failed to delete template %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
+                s_logger.error(errorMessage, e);
+                return new Answer(cmd, false, errorMessage);
+            }
+        } else if (dstore instanceof SwiftTO) {
+            SwiftTO swift = (SwiftTO)dstore;
+            String container = "T-" + obj.getId();
+            String object = "";
+
+            try {
+                String result = swiftDelete(swift, container, object);
+                if (result != null) {
+                    String errMsg = "failed to delete object " + container + "/" + object + " , err=" + result;
+                    s_logger.warn(errMsg);
+                    return new Answer(cmd, false, errMsg);
+                }
+                return new Answer(cmd, true, "success");
+            } catch (Exception e) {
+                String errMsg = cmd + " Command failed due to " + e.toString();
+                s_logger.warn(errMsg, e);
+                return new Answer(cmd, false, errMsg);
+            }
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
+        }
+    }
+
+    protected Answer deleteVolume(final DeleteCommand cmd) {
+        DataTO obj = cmd.getData();
+        DataStoreTO dstore = obj.getDataStore();
+        if (dstore instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)dstore;
+            String relativeVolumePath = obj.getPath();
+            String parent = getRootDir(nfs.getUrl());
+
+            if (relativeVolumePath.startsWith(File.separator)) {
+                relativeVolumePath = relativeVolumePath.substring(1);
+            }
+
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
+            String absoluteVolumePath = parent + relativeVolumePath;
+            File volPath = new File(absoluteVolumePath);
+            File tmpltParent = null;
+            if (volPath.exists() && volPath.isDirectory()) {
+                // for vmware, absoluteVolumePath represents a directory where volume files are located.
+                tmpltParent = volPath;
+            } else {
+                // for other hypervisors, the volume .vhd or .qcow2 file path is passed
+                tmpltParent = new File(absoluteVolumePath).getParentFile();
+            }
+            String details = null;
+            if (!tmpltParent.exists()) {
+                details = "volume parent directory " + tmpltParent.getName() + " doesn't exist";
+                s_logger.debug(details);
+                return new Answer(cmd, true, details);
+            }
+            File[] tmpltFiles = tmpltParent.listFiles();
+            if (tmpltFiles == null || tmpltFiles.length == 0) {
+                details = "No files under volume parent directory " + tmpltParent.getName();
+                s_logger.debug(details);
+            } else {
+                boolean found = false;
+                for (File f : tmpltFiles) {
+                    if (!found && f.getName().equals("volume.properties")) {
+                        found = true;
+                    }
+
+                    // KVM HA monitor makes a mess in the templates with its
+                    // heartbeat tests
+                    // Don't let this stop us from cleaning up the template
+                    if (f.isDirectory() && f.getName().equals("KVMHA")) {
+                        s_logger.debug("Deleting KVMHA directory contents from template location");
+                        File[] haFiles = f.listFiles();
+                        for (File haFile : haFiles) {
+                            haFile.delete();
+                        }
+                    }
+
+                    if (!f.delete()) {
+                        return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Volume path " + tmpltParent.getPath());
+                    }
+                }
+                if (!found) {
+                    details = "Can not find volume.properties under " + tmpltParent.getName();
+                    s_logger.debug(details);
+                }
+            }
+            if (!tmpltParent.delete()) {
+                details = "Unable to delete directory " + tmpltParent.getName() + " under Volume path " + tmpltParent.getPath();
+                s_logger.debug(details);
+                return new Answer(cmd, false, details);
+            }
+            return new Answer(cmd, true, null);
+        } else if (dstore instanceof S3TO) {
+            final S3TO s3 = (S3TO)dstore;
+            final String path = obj.getPath();
+            final String bucket = s3.getBucketName();
+            try {
+                S3Utils.deleteDirectory(s3, bucket, path);
+                return new Answer(cmd, true, String.format("Deleted volume %1%s from bucket %2$s.", path, bucket));
+            } catch (Exception e) {
+                final String errorMessage = String.format("Failed to delete volume %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
+                s_logger.error(errorMessage, e);
+                return new Answer(cmd, false, errorMessage);
+            }
+        } else if (dstore instanceof SwiftTO) {
+            Long volumeId = obj.getId();
+            String path = obj.getPath();
+            String filename = StringUtils.substringAfterLast(path, "/"); // assuming
+            // that
+            // the
+            // filename
+            // is
+            // the
+            // last
+            // section
+            // in
+            // the
+            // path
+            String result = swiftDelete((SwiftTO)dstore, "V-" + volumeId.toString(), filename);
+            if (result != null) {
+                String errMsg = "failed to delete volume " + filename + " , err=" + result;
+                s_logger.warn(errMsg);
+                return new Answer(cmd, false, errMsg);
+            }
+            return new Answer(cmd, true, "Deleted volume " + path + " from swift");
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
+        }
+
+    }
+
+    @Override
+    synchronized public String getRootDir(String secUrl) {
+        if (!_inSystemVM) {
+            return _parent;
+        }
+        try {
+            URI uri = new URI(secUrl);
+            String dir = mountUri(uri);
+            return _parent + "/" + dir;
+        } catch (Exception e) {
+            String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
+            s_logger.error(msg, e);
+            throw new CloudRuntimeException(msg);
+        }
+    }
+
+    protected long getUsedSize(String rootDir) {
+        return _storage.getUsedSpace(rootDir);
+    }
+
+    protected long getTotalSize(String rootDir) {
+        return _storage.getTotalSpace(rootDir);
+    }
+
+    protected long convertFilesystemSize(final String size) {
+        if (size == null || size.isEmpty()) {
+            return -1;
+        }
+
+        long multiplier = 1;
+        if (size.endsWith("T")) {
+            multiplier = 1024l * 1024l * 1024l * 1024l;
+        } else if (size.endsWith("G")) {
+            multiplier = 1024l * 1024l * 1024l;
+        } else if (size.endsWith("M")) {
+            multiplier = 1024l * 1024l;
+        } else {
+            assert (false) : "Well, I have no idea what this is: " + size;
+        }
+
+        return (long)(Double.parseDouble(size.substring(0, size.length() - 1)) * multiplier);
+    }
+
+    @Override
+    public Type getType() {
+        if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) {
+            return Host.Type.SecondaryStorage;
+        }
+
+        return Host.Type.SecondaryStorageCmdExecutor;
+    }
+
+    @Override
+    public PingCommand getCurrentStatus(final long id) {
+        return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        _eth1ip = (String)params.get("eth1ip");
+        _eth1mask = (String)params.get("eth1mask");
+        if (_eth1ip != null) { // can only happen inside service vm
+            params.put("private.network.device", "eth1");
+        } else {
+            s_logger.warn("eth1ip parameter has not been configured, assuming that we are not inside a system vm");
+        }
+        String eth2ip = (String)params.get("eth2ip");
+        if (eth2ip != null) {
+            params.put("public.network.device", "eth2");
+        }
+        _publicIp = (String)params.get("eth2ip");
+        _hostname = (String)params.get("name");
+
+        String inSystemVM = (String)params.get("secondary.storage.vm");
+        if (inSystemVM == null || "true".equalsIgnoreCase(inSystemVM)) {
+            s_logger.debug("conf secondary.storage.vm is true, act as if executing in SSVM");
+            _inSystemVM = true;
+        }
+
+        _storageIp = (String)params.get("storageip");
+        if (_storageIp == null && _inSystemVM) {
+            s_logger.warn("There is no storageip in /proc/cmdline, something wrong!");
+        }
+        _storageNetmask = (String)params.get("storagenetmask");
+        _storageGateway = (String)params.get("storagegateway");
+        super.configure(name, params);
+
+        _params = params;
+        String value = (String)params.get("scripts.timeout");
+        _timeout = NumbersUtil.parseInt(value, 1440) * 1000;
+
+        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
+        configureStorageLayerClass(params);
+
+        if (_inSystemVM) {
+            _storage.mkdirs(_parent);
+        }
+
+        _configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh");
+        if (_configSslScr != null) {
+            s_logger.info("config_ssl.sh found in " + _configSslScr);
+        }
+
+        _configAuthScr = Script.findScript(getDefaultScriptsDir(), "config_auth.sh");
+        if (_configSslScr != null) {
+            s_logger.info("config_auth.sh found in " + _configAuthScr);
+        }
+
+        _configIpFirewallScr = Script.findScript(getDefaultScriptsDir(), "ipfirewall.sh");
+        if (_configIpFirewallScr != null) {
+            s_logger.info("_configIpFirewallScr found in " + _configIpFirewallScr);
+        }
+
+        createTemplateFromSnapshotXenScript = Script.findScript(getDefaultScriptsDir(), "create_privatetemplate_from_snapshot_xen.sh");
+        if (createTemplateFromSnapshotXenScript == null) {
+            throw new ConfigurationException("create_privatetemplate_from_snapshot_xen.sh not found in " + getDefaultScriptsDir());
+        }
+
+        _role = (String)params.get("role");
+        if (_role == null) {
+            _role = SecondaryStorageVm.Role.templateProcessor.toString();
+        }
+        s_logger.info("Secondary storage runs in role " + _role);
+
+        _guid = (String)params.get("guid");
+        if (_guid == null) {
+            throw new ConfigurationException("Unable to find the guid");
+        }
+
+        _dc = (String)params.get("zone");
+        if (_dc == null) {
+            throw new ConfigurationException("Unable to find the zone");
+        }
+        _pod = (String)params.get("pod");
+
+        _instance = (String)params.get("instance");
+
+        if (!_inSystemVM) {
+            _parent = (String)params.get("mount.path");
+        }
+
+        if (_inSystemVM) {
+            _localgw = (String)params.get("localgw");
+            if (_localgw != null) { // can only happen inside service vm
+                String mgmtHost = (String)params.get("host");
+                addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
+
+                String internalDns1 = (String)params.get("internaldns1");
+                if (internalDns1 == null) {
+                    s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
+                } else {
+                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
+                }
+
+                String internalDns2 = (String)params.get("internaldns2");
+                if (internalDns2 != null) {
+                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
+                }
+
+            }
+
+            startAdditionalServices();
+            _params.put("install.numthreads", "50");
+            _params.put("secondary.storage.vm", "true");
+        }
+
+        try {
+            _params.put(StorageLayer.InstanceConfigKey, _storage);
+            _dlMgr = new DownloadManagerImpl();
+            _dlMgr.configure("DownloadManager", _params);
+            _upldMgr = new UploadManagerImpl();
+            _upldMgr.configure("UploadManager", params);
+        } catch (ConfigurationException e) {
+            s_logger.warn("Caught problem while configuring DownloadManager", e);
+            return false;
+        }
+        return true;
+    }
+
+    protected void configureStorageLayerClass(Map<String, Object> params) throws ConfigurationException {
+        String value;
+        if (_storage == null) {
+            value = (String)params.get(StorageLayer.ClassConfigKey);
+            if (value == null) {
+                value = "com.cloud.storage.JavaStorageLayer";
+            }
+
+            try {
+                Class<?> clazz = Class.forName(value);
+                _storage = (StorageLayer)clazz.newInstance();
+            

<TRUNCATED>

[04/50] [abbrv] Moved the secondary storage service into its own server directory

Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4be3b993/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
deleted file mode 100755
index 9782c2e..0000000
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ /dev/null
@@ -1,2430 +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.storage.resource;
-
-import static com.cloud.utils.S3Utils.mputFile;
-import static com.cloud.utils.S3Utils.putFile;
-import static com.cloud.utils.StringUtils.join;
-import static java.lang.String.format;
-import static java.util.Arrays.asList;
-import static org.apache.commons.lang.StringUtils.substringAfterLast;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.net.URI;
-import java.net.UnknownHostException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.utils.URLEncodedUtils;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.log4j.Logger;
-
-import com.amazonaws.services.s3.model.S3ObjectSummary;
-
-import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
-import org.apache.cloudstack.storage.command.CopyCmdAnswer;
-import org.apache.cloudstack.storage.command.CopyCommand;
-import org.apache.cloudstack.storage.command.DeleteCommand;
-import org.apache.cloudstack.storage.command.DownloadCommand;
-import org.apache.cloudstack.storage.command.DownloadProgressCommand;
-import org.apache.cloudstack.storage.template.DownloadManager;
-import org.apache.cloudstack.storage.template.DownloadManagerImpl;
-import org.apache.cloudstack.storage.template.DownloadManagerImpl.ZfsPathParser;
-import org.apache.cloudstack.storage.template.UploadManager;
-import org.apache.cloudstack.storage.template.UploadManagerImpl;
-import org.apache.cloudstack.storage.to.SnapshotObjectTO;
-import org.apache.cloudstack.storage.to.TemplateObjectTO;
-import org.apache.cloudstack.storage.to.VolumeObjectTO;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.CheckHealthAnswer;
-import com.cloud.agent.api.CheckHealthCommand;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.ComputeChecksumCommand;
-import com.cloud.agent.api.DeleteSnapshotsDirCommand;
-import com.cloud.agent.api.GetStorageStatsAnswer;
-import com.cloud.agent.api.GetStorageStatsCommand;
-import com.cloud.agent.api.PingCommand;
-import com.cloud.agent.api.PingStorageCommand;
-import com.cloud.agent.api.ReadyAnswer;
-import com.cloud.agent.api.ReadyCommand;
-import com.cloud.agent.api.SecStorageFirewallCfgCommand;
-import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
-import com.cloud.agent.api.SecStorageSetupAnswer;
-import com.cloud.agent.api.SecStorageSetupCommand;
-import com.cloud.agent.api.SecStorageVMSetupCommand;
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupSecondaryStorageCommand;
-import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
-import com.cloud.agent.api.storage.DownloadAnswer;
-import com.cloud.agent.api.storage.ListTemplateAnswer;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.storage.ListVolumeAnswer;
-import com.cloud.agent.api.storage.ListVolumeCommand;
-import com.cloud.agent.api.storage.UploadCommand;
-import com.cloud.agent.api.to.DataObjectType;
-import com.cloud.agent.api.to.DataStoreTO;
-import com.cloud.agent.api.to.DataTO;
-import com.cloud.agent.api.to.NfsTO;
-import com.cloud.agent.api.to.S3TO;
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.exception.InternalErrorException;
-import com.cloud.host.Host;
-import com.cloud.host.Host.Type;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.resource.ServerResourceBase;
-import com.cloud.storage.DataStoreRole;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.StorageLayer;
-import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.template.OVAProcessor;
-import com.cloud.storage.template.Processor;
-import com.cloud.storage.template.Processor.FormatInfo;
-import com.cloud.storage.template.QCOW2Processor;
-import com.cloud.storage.template.RawImageProcessor;
-import com.cloud.storage.template.TemplateLocation;
-import com.cloud.storage.template.TemplateProp;
-import com.cloud.storage.template.VhdProcessor;
-import com.cloud.storage.template.VmdkProcessor;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.S3Utils;
-import com.cloud.utils.S3Utils.FileNamingStrategy;
-import com.cloud.utils.SwiftUtil;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.NetUtils;
-import com.cloud.utils.script.OutputInterpreter;
-import com.cloud.utils.script.Script;
-import com.cloud.vm.SecondaryStorageVm;
-
-public class NfsSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
-
-    private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResource.class);
-
-    private static final String TEMPLATE_ROOT_DIR = "template/tmpl";
-    private static final String VOLUME_ROOT_DIR = "volumes";
-
-    int _timeout;
-
-    public int getTimeout() {
-        return _timeout;
-    }
-
-    public void setTimeout(int timeout) {
-        _timeout = timeout;
-    }
-
-    String _instance;
-    String _dc;
-    String _pod;
-    String _guid;
-    String _role;
-    Map<String, Object> _params;
-    protected StorageLayer _storage;
-    protected boolean _inSystemVM = false;
-    boolean _sslCopy = false;
-
-    protected DownloadManager _dlMgr;
-    protected UploadManager _upldMgr;
-    private String _configSslScr;
-    private String _configAuthScr;
-    private String _configIpFirewallScr;
-    private String _publicIp;
-    private String _hostname;
-    private String _localgw;
-    private String _eth1mask;
-    private String _eth1ip;
-    private String _storageIp;
-    private String _storageNetmask;
-    private String _storageGateway;
-    private final List<String> nfsIps = new ArrayList<String>();
-    protected String _parent = "/mnt/SecStorage";
-    final private String _tmpltpp = "template.properties";
-    protected String createTemplateFromSnapshotXenScript;
-
-    public void setParentPath(String path) {
-        _parent = path;
-    }
-
-    public String getMountingRoot() {
-        return _parent;
-    }
-
-    @Override
-    public void disconnected() {
-    }
-
-    public void setInSystemVM(boolean inSystemVM) {
-        _inSystemVM = inSystemVM;
-    }
-
-    @Override
-    public Answer executeRequest(Command cmd) {
-        if (cmd instanceof DownloadProgressCommand) {
-            return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
-        } else if (cmd instanceof DownloadCommand) {
-            return execute((DownloadCommand)cmd);
-        } else if (cmd instanceof UploadCommand) {
-            return _upldMgr.handleUploadCommand(this, (UploadCommand)cmd);
-        } else if (cmd instanceof CreateEntityDownloadURLCommand) {
-            return _upldMgr.handleCreateEntityURLCommand((CreateEntityDownloadURLCommand)cmd);
-        } else if (cmd instanceof DeleteEntityDownloadURLCommand) {
-            return _upldMgr.handleDeleteEntityDownloadURLCommand((DeleteEntityDownloadURLCommand)cmd);
-        } else if (cmd instanceof GetStorageStatsCommand) {
-            return execute((GetStorageStatsCommand)cmd);
-        } else if (cmd instanceof CheckHealthCommand) {
-            return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
-        } else if (cmd instanceof ReadyCommand) {
-            return new ReadyAnswer((ReadyCommand)cmd);
-        } else if (cmd instanceof SecStorageFirewallCfgCommand) {
-            return execute((SecStorageFirewallCfgCommand)cmd);
-        } else if (cmd instanceof SecStorageVMSetupCommand) {
-            return execute((SecStorageVMSetupCommand)cmd);
-        } else if (cmd instanceof SecStorageSetupCommand) {
-            return execute((SecStorageSetupCommand)cmd);
-        } else if (cmd instanceof ComputeChecksumCommand) {
-            return execute((ComputeChecksumCommand)cmd);
-        } else if (cmd instanceof ListTemplateCommand) {
-            return execute((ListTemplateCommand)cmd);
-        } else if (cmd instanceof ListVolumeCommand) {
-            return execute((ListVolumeCommand)cmd);
-        } else if (cmd instanceof DeleteSnapshotsDirCommand) {
-            return execute((DeleteSnapshotsDirCommand)cmd);
-        } else if (cmd instanceof CopyCommand) {
-            return execute((CopyCommand)cmd);
-        } else if (cmd instanceof DeleteCommand) {
-            return execute((DeleteCommand)cmd);
-        } else {
-            return Answer.createUnsupportedCommandAnswer(cmd);
-        }
-    }
-
-    protected CopyCmdAnswer postProcessing(File destFile, String downloadPath, String destPath, DataTO srcData, DataTO destData) throws ConfigurationException {
-        if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
-            SnapshotObjectTO snapshot = new SnapshotObjectTO();
-            snapshot.setPath(destPath + File.separator + destFile.getName());
-
-            CopyCmdAnswer answer = new CopyCmdAnswer(snapshot);
-            return answer;
-        }
-        // do post processing to unzip the file if it is compressed
-        String scriptsDir = "scripts/storage/secondary";
-        String createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
-        if (createTmpltScr == null) {
-            throw new ConfigurationException("Unable to find createtmplt.sh");
-        }
-        s_logger.info("createtmplt.sh found in " + createTmpltScr);
-        String createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
-        if (createVolScr == null) {
-            throw new ConfigurationException("Unable to find createvolume.sh");
-        }
-        s_logger.info("createvolume.sh found in " + createVolScr);
-        String script = srcData.getObjectType() == DataObjectType.TEMPLATE ? createTmpltScr : createVolScr;
-
-        int installTimeoutPerGig = 180 * 60 * 1000;
-        long imgSizeGigs = (long)Math.ceil(destFile.length() * 1.0d / (1024 * 1024 * 1024));
-        imgSizeGigs++; // add one just in case
-        long timeout = imgSizeGigs * installTimeoutPerGig;
-
-        String origPath = destFile.getAbsolutePath();
-        String extension = null;
-        if (srcData.getObjectType() == DataObjectType.TEMPLATE) {
-            extension = ((TemplateObjectTO)srcData).getFormat().getFileExtension();
-        } else if (srcData.getObjectType() == DataObjectType.VOLUME) {
-            extension = ((VolumeObjectTO)srcData).getFormat().getFileExtension();
-        }
-
-        String templateName = UUID.randomUUID().toString();
-        String templateFilename = templateName + "." + extension;
-        Script scr = new Script(script, timeout, s_logger);
-        scr.add("-s", Long.toString(imgSizeGigs)); // not used for now
-        scr.add("-n", templateFilename);
-
-        scr.add("-t", downloadPath);
-        scr.add("-f", origPath); // this is the temporary
-        // template file downloaded
-        String result;
-        result = scr.execute();
-
-        if (result != null) {
-            // script execution failure
-            throw new CloudRuntimeException("Failed to run script " + script);
-        }
-
-        String finalFileName = templateFilename;
-        String finalDownloadPath = destPath + File.separator + templateFilename;
-        // compute the size of
-        long size = _storage.getSize(downloadPath + File.separator + templateFilename);
-
-        DataTO newDestTO = null;
-
-        if (destData.getObjectType() == DataObjectType.TEMPLATE) {
-            TemplateObjectTO newTemplTO = new TemplateObjectTO();
-            newTemplTO.setPath(finalDownloadPath);
-            newTemplTO.setName(finalFileName);
-            newTemplTO.setSize(size);
-            newTemplTO.setPhysicalSize(size);
-            newDestTO = newTemplTO;
-        } else {
-            VolumeObjectTO newVolTO = new VolumeObjectTO();
-            newVolTO.setPath(finalDownloadPath);
-            newVolTO.setName(finalFileName);
-            newVolTO.setSize(size);
-            newDestTO = newVolTO;
-        }
-
-        return new CopyCmdAnswer(newDestTO);
-    }
-
-    protected Answer copyFromSwiftToNfs(CopyCommand cmd, DataTO srcData, SwiftTO swiftTO, DataTO destData, NfsTO destImageStore) {
-        final String storagePath = destImageStore.getUrl();
-        final String destPath = destData.getPath();
-        try {
-            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
-            final File downloadDirectory = _storage.getFile(downloadPath);
-            if (!downloadDirectory.mkdirs()) {
-                return new CopyCmdAnswer("Failed to create download directory " + downloadPath);
-            }
-            File destFile = SwiftUtil.getObject(swiftTO, downloadDirectory, srcData.getPath());
-            return postProcessing(destFile, downloadPath, destPath, srcData, destData);
-        } catch (Exception e) {
-            s_logger.debug("Failed to copy swift to nfs", e);
-            return new CopyCmdAnswer(e.toString());
-        }
-    }
-
-    protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataTO destData, NfsTO destImageStore) {
-        final String storagePath = destImageStore.getUrl();
-        final String destPath = destData.getPath();
-
-        try {
-
-            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
-            final File downloadDirectory = _storage.getFile(downloadPath);
-
-            if (!downloadDirectory.mkdirs()) {
-                final String errMsg = "Unable to create directory " + downloadPath + " to copy from S3 to cache.";
-                s_logger.error(errMsg);
-                return new CopyCmdAnswer(errMsg);
-            } else {
-                s_logger.debug("Directory " + downloadPath + " already exists");
-            }
-
-            File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory, new FileNamingStrategy() {
-                @Override
-                public String determineFileName(final String key) {
-                    return substringAfterLast(key, S3Utils.SEPARATOR);
-                }
-            });
-
-            if (destFile == null) {
-                return new CopyCmdAnswer("Can't find template");
-            }
-
-            return postProcessing(destFile, downloadPath, destPath, srcData, destData);
-        } catch (Exception e) {
-
-            final String errMsg = format("Failed to download" + "due to $2%s", e.getMessage());
-            s_logger.error(errMsg, e);
-            return new CopyCmdAnswer(errMsg);
-        }
-    }
-
-    protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData,
-            NfsTO destDataStore) {
-        String srcMountPoint = getRootDir(srcDataStore.getUrl());
-        String snapshotPath = srcData.getPath();
-        int index = snapshotPath.lastIndexOf("/");
-        String snapshotName = snapshotPath.substring(index + 1);
-        if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
-            snapshotName = snapshotName + ".vhd";
-        }
-        snapshotPath = snapshotPath.substring(0, index);
-
-        snapshotPath = srcMountPoint + File.separator + snapshotPath;
-        String destMountPoint = getRootDir(destDataStore.getUrl());
-        String destPath = destMountPoint + File.separator + destData.getPath();
-
-        String errMsg = null;
-        try {
-            _storage.mkdir(destPath);
-
-            String templateUuid = UUID.randomUUID().toString();
-            String templateName = templateUuid + ".vhd";
-            Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
-            command.add("-p", snapshotPath);
-            command.add("-s", snapshotName);
-            command.add("-n", templateName);
-            command.add("-t", destPath);
-            String result = command.execute();
-
-            if (result != null && !result.equalsIgnoreCase("")) {
-                return new CopyCmdAnswer(result);
-            }
-
-            Map<String, Object> params = new HashMap<String, Object>();
-            params.put(StorageLayer.InstanceConfigKey, _storage);
-            Processor processor = new VhdProcessor();
-
-            processor.configure("Vhd Processor", params);
-            FormatInfo info = processor.process(destPath, null, templateUuid);
-
-            TemplateLocation loc = new TemplateLocation(_storage, destPath);
-            loc.create(1, true, templateUuid);
-            loc.addFormat(info);
-            loc.save();
-            TemplateProp prop = loc.getTemplateInfo();
-            TemplateObjectTO newTemplate = new TemplateObjectTO();
-            newTemplate.setPath(destData.getPath() + File.separator + templateName);
-            newTemplate.setFormat(ImageFormat.VHD);
-            newTemplate.setSize(prop.getSize());
-            newTemplate.setPhysicalSize(prop.getPhysicalSize());
-            newTemplate.setName(templateUuid);
-            return new CopyCmdAnswer(newTemplate);
-        } catch (ConfigurationException e) {
-            s_logger.debug("Failed to create template from snapshot: " + e.toString());
-            errMsg = e.toString();
-        } catch (InternalErrorException e) {
-            s_logger.debug("Failed to create template from snapshot: " + e.toString());
-            errMsg = e.toString();
-        } catch (IOException e) {
-            s_logger.debug("Failed to create template from snapshot: " + e.toString());
-            errMsg = e.toString();
-        }
-
-        return new CopyCmdAnswer(errMsg);
-    }
-
-    protected Answer copySnapshotToTemplateFromNfsToNfs(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
-
-        if (srcData.getHypervisorType() == HypervisorType.XenServer) {
-            return copySnapshotToTemplateFromNfsToNfsXenserver(cmd, srcData, srcDataStore, destData, destDataStore);
-        } else if (srcData.getHypervisorType() == HypervisorType.KVM) {
-            File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl());
-            File destFile = getFile(destData.getPath(), destDataStore.getUrl());
-
-            VolumeObjectTO volumeObjectTO = srcData.getVolume();
-            ImageFormat srcFormat = null;
-            //TODO: the image format should be stored in snapshot table, instead of getting from volume
-            if (volumeObjectTO != null) {
-                srcFormat = volumeObjectTO.getFormat();
-            } else {
-                srcFormat = ImageFormat.QCOW2;
-            }
-
-            // get snapshot file name
-            String templateName = srcFile.getName();
-            // add kvm file extension for copied template name
-            String fileName = templateName + "." + srcFormat.getFileExtension();
-            String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName;
-            s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath);
-            Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
-            try {
-                // generate template.properties file
-                String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
-                _storage.create(destFile.getAbsolutePath(), "template.properties");
-                File metaFile = new File(metaFileName);
-                FileWriter writer = new FileWriter(metaFile);
-                BufferedWriter bufferWriter = new BufferedWriter(writer);
-                // KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need
-                // to send template name back.
-                bufferWriter.write("uniquename=" + destData.getName());
-                bufferWriter.write("\n");
-                bufferWriter.write("filename=" + fileName);
-                bufferWriter.write("\n");
-                long size = _storage.getSize(destFileFullPath);
-                bufferWriter.write("size=" + size);
-                bufferWriter.close();
-                writer.close();
-
-                /**
-                 * Snapshots might be in either QCOW2 or RAW image format
-                 *
-                 * For example RBD snapshots are in RAW format
-                 */
-                Processor processor = null;
-                if (srcFormat == ImageFormat.QCOW2) {
-                    processor = new QCOW2Processor();
-                } else if (srcFormat == ImageFormat.RAW) {
-                    processor = new RawImageProcessor();
-                } else {
-                    throw new ConfigurationException("Unknown image format " + srcFormat.toString());
-                }
-
-                Map<String, Object> params = new HashMap<String, Object>();
-                params.put(StorageLayer.InstanceConfigKey, _storage);
-
-                processor.configure("template processor", params);
-                String destPath = destFile.getAbsolutePath();
-
-                FormatInfo info = processor.process(destPath, null, templateName);
-                TemplateLocation loc = new TemplateLocation(_storage, destPath);
-                loc.create(1, true, destData.getName());
-                loc.addFormat(info);
-                loc.save();
-
-                TemplateProp prop = loc.getTemplateInfo();
-                TemplateObjectTO newTemplate = new TemplateObjectTO();
-                newTemplate.setPath(destData.getPath() + File.separator + fileName);
-                newTemplate.setFormat(srcFormat);
-                newTemplate.setSize(prop.getSize());
-                newTemplate.setPhysicalSize(prop.getPhysicalSize());
-                return new CopyCmdAnswer(newTemplate);
-            } catch (ConfigurationException e) {
-                s_logger.debug("Failed to create template:" + e.toString());
-                return new CopyCmdAnswer(e.toString());
-            } catch (IOException e) {
-                s_logger.debug("Failed to create template:" + e.toString());
-                return new CopyCmdAnswer(e.toString());
-            } catch (InternalErrorException e) {
-                s_logger.debug("Failed to create template:" + e.toString());
-                return new CopyCmdAnswer(e.toString());
-            }
-        }
-
-        return new CopyCmdAnswer("");
-    }
-
-    protected File getFile(String path, String nfsPath) {
-        String filePath = getRootDir(nfsPath) + File.separator + path;
-        File f = new File(filePath);
-        if (!f.exists()) {
-            _storage.mkdirs(filePath);
-            f = new File(filePath);
-        }
-        return f;
-    }
-
-    protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
-        DataTO srcData = cmd.getSrcTO();
-        DataTO destData = cmd.getDestTO();
-        DataStoreTO srcDataStore = srcData.getDataStore();
-        DataStoreTO destDataStore = destData.getDataStore();
-        if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
-            if (!(srcDataStore instanceof NfsTO)) {
-                s_logger.debug("only support nfs storage as src, when create template from snapshot");
-                return Answer.createUnsupportedCommandAnswer(cmd);
-            }
-
-            if (destDataStore instanceof NfsTO) {
-                return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData, (NfsTO)destDataStore);
-            } else if (destDataStore instanceof SwiftTO) {
-                //create template on the same data store
-                CopyCmdAnswer answer =
-                        (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData,
-                                (NfsTO)srcDataStore);
-                if (!answer.getResult()) {
-                    return answer;
-                }
-                s_logger.debug("starting copy template to swift");
-                DataTO newTemplate = answer.getNewData();
-                File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl());
-                SwiftTO swift = (SwiftTO)destDataStore;
-                String containterName = SwiftUtil.getContainerName(destData.getObjectType().toString(), destData.getId());
-                String swiftPath = SwiftUtil.putObject(swift, templateFile, containterName, templateFile.getName());
-                //upload template.properties
-                File properties = new File(templateFile.getParent() + File.separator + _tmpltpp);
-                if (properties.exists()) {
-                    SwiftUtil.putObject(swift, properties, containterName, _tmpltpp);
-                }
-
-                //clean up template data on staging area
-                try {
-                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
-                    execute(deleteCommand);
-                } catch (Exception e) {
-                    s_logger.debug("Failed to clean up staging area:", e);
-                }
-
-                TemplateObjectTO template = new TemplateObjectTO();
-                template.setPath(swiftPath);
-                template.setSize(templateFile.length());
-                template.setPhysicalSize(template.getSize());
-                SnapshotObjectTO snapshot = (SnapshotObjectTO)srcData;
-                template.setFormat(snapshot.getVolume().getFormat());
-                return new CopyCmdAnswer(template);
-            } else if (destDataStore instanceof S3TO) {
-                //create template on the same data store
-                CopyCmdAnswer answer =
-                        (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO)srcData, (NfsTO)srcDataStore, (TemplateObjectTO)destData,
-                                (NfsTO)srcDataStore);
-                if (!answer.getResult()) {
-                    return answer;
-                }
-                TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData();
-                newTemplate.setDataStore(srcDataStore);
-                CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
-                Answer result = copyFromNfsToS3(newCpyCmd);
-                //clean up template data on staging area
-                try {
-                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
-                    execute(deleteCommand);
-                } catch (Exception e) {
-                    s_logger.debug("Failed to clean up staging area:", e);
-                }
-                return result;
-            }
-        }
-        s_logger.debug("Failed to create templat from snapshot");
-        return new CopyCmdAnswer("Unsupported prototcol");
-    }
-
-    protected Answer copyFromNfsToImage(CopyCommand cmd) {
-        DataTO destData = cmd.getDestTO();
-        DataStoreTO destDataStore = destData.getDataStore();
-
-        if (destDataStore instanceof S3TO) {
-            return copyFromNfsToS3(cmd);
-        } else {
-            return new CopyCmdAnswer("unsupported ");
-        }
-    }
-
-    protected Answer execute(CopyCommand cmd) {
-        DataTO srcData = cmd.getSrcTO();
-        DataTO destData = cmd.getDestTO();
-        DataStoreTO srcDataStore = srcData.getDataStore();
-        DataStoreTO destDataStore = destData.getDataStore();
-
-        if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
-            return createTemplateFromSnapshot(cmd);
-        }
-
-        if (destDataStore instanceof NfsTO && destDataStore.getRole() == DataStoreRole.ImageCache) {
-            NfsTO destImageStore = (NfsTO)destDataStore;
-            if (srcDataStore instanceof S3TO) {
-                S3TO s3 = (S3TO)srcDataStore;
-                return copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore);
-            } else if (srcDataStore instanceof SwiftTO) {
-                return copyFromSwiftToNfs(cmd, srcData, (SwiftTO)srcDataStore, destData, destImageStore);
-            }
-        }
-
-        if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
-            return copyFromNfsToImage(cmd);
-        }
-
-        return Answer.createUnsupportedCommandAnswer(cmd);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected String determineS3TemplateDirectory(final Long accountId, final Long templateId, final String templateUniqueName) {
-        return join(asList(TEMPLATE_ROOT_DIR, accountId, templateId, templateUniqueName), S3Utils.SEPARATOR);
-    }
-
-    private String determineS3TemplateNameFromKey(String key) {
-        return StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected String determineS3VolumeDirectory(final Long accountId, final Long volId) {
-        return join(asList(VOLUME_ROOT_DIR, accountId, volId), S3Utils.SEPARATOR);
-    }
-
-    protected Long determineS3VolumeIdFromKey(String key) {
-        return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR));
-    }
-
-    private String determineStorageTemplatePath(final String storagePath, String dataPath) {
-        return join(asList(getRootDir(storagePath), dataPath), File.separator);
-    }
-
-    protected File downloadFromUrlToNfs(String url, NfsTO nfs, String path, String name) {
-        HttpClient client = new DefaultHttpClient();
-        HttpGet get = new HttpGet(url);
-        try {
-            HttpResponse response = client.execute(get);
-            HttpEntity entity = response.getEntity();
-            if (entity == null) {
-                s_logger.debug("Faled to get entity");
-                throw new CloudRuntimeException("Failed to get url: " + url);
-            }
-
-            String nfsMountPath = getRootDir(nfs.getUrl());
-
-            String filePath = nfsMountPath + File.separator + path;
-            File directory = new File(filePath);
-            if (!directory.exists()) {
-                _storage.mkdirs(filePath);
-            }
-            File destFile = new File(filePath + File.separator + name);
-            if (!destFile.createNewFile()) {
-                s_logger.warn("Reusing existing file " + destFile.getPath());
-            }
-            FileOutputStream outputStream = new FileOutputStream(destFile);
-            entity.writeTo(outputStream);
-            return new File(destFile.getAbsolutePath());
-        } catch (IOException e) {
-            s_logger.debug("Faild to get url:" + url + ", due to " + e.toString());
-            throw new CloudRuntimeException(e);
-        }
-    }
-
-    protected Answer registerTemplateOnSwift(DownloadCommand cmd) {
-        SwiftTO swiftTO = (SwiftTO)cmd.getDataStore();
-        String path = cmd.getInstallPath();
-        DataStoreTO cacheStore = cmd.getCacheStore();
-        if (cacheStore == null || !(cacheStore instanceof NfsTO)) {
-            return new DownloadAnswer("cache store can't be null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-        }
-
-        File file = null;
-        try {
-            NfsTO nfsCacheStore = (NfsTO)cacheStore;
-            String fileName = cmd.getName() + "." + cmd.getFormat().getFileExtension();
-            file = downloadFromUrlToNfs(cmd.getUrl(), nfsCacheStore, path, fileName);
-            String container = "T-" + cmd.getId();
-            String swiftPath = SwiftUtil.putObject(swiftTO, file, container, null);
-
-            //put metda file
-            File uniqDir = _storage.createUniqDir();
-            String metaFileName = uniqDir.getAbsolutePath() + File.separator + "template.properties";
-            _storage.create(uniqDir.getAbsolutePath(), "template.properties");
-            File metaFile = new File(metaFileName);
-            FileWriter writer = new FileWriter(metaFile);
-            BufferedWriter bufferWriter = new BufferedWriter(writer);
-            bufferWriter.write("uniquename=" + cmd.getName());
-            bufferWriter.write("\n");
-            bufferWriter.write("filename=" + fileName);
-            bufferWriter.write("\n");
-            bufferWriter.write("size=" + file.length());
-            bufferWriter.close();
-            writer.close();
-
-            SwiftUtil.putObject(swiftTO, metaFile, container, "template.properties");
-            metaFile.delete();
-            uniqDir.delete();
-            String md5sum = null;
-            try {
-                md5sum = DigestUtils.md5Hex(new FileInputStream(file));
-            } catch (IOException e) {
-                s_logger.debug("Failed to get md5sum: " + file.getAbsoluteFile());
-            }
-
-            DownloadAnswer answer =
-                    new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, swiftPath, swiftPath, file.length(), file.length(), md5sum);
-            return answer;
-        } catch (IOException e) {
-            s_logger.debug("Failed to register template into swift", e);
-            return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-        } finally {
-            if (file != null) {
-                file.delete();
-            }
-        }
-    }
-
-    private Answer execute(DownloadCommand cmd) {
-        DataStoreTO dstore = cmd.getDataStore();
-        if (dstore instanceof NfsTO || dstore instanceof S3TO) {
-            return _dlMgr.handleDownloadCommand(this, cmd);
-        } else if (dstore instanceof SwiftTO) {
-            return registerTemplateOnSwift(cmd);
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
-        }
-
-    }
-
-    private ImageFormat getTemplateFormat(String filePath) {
-        String ext = null;
-        int extensionPos = filePath.lastIndexOf('.');
-        int lastSeparator = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
-        int i = lastSeparator > extensionPos ? -1 : extensionPos;
-        if (i > 0) {
-            ext = filePath.substring(i + 1);
-        }
-        if (ext != null) {
-            if (ext.equalsIgnoreCase("vhd")) {
-                return ImageFormat.VHD;
-            } else if (ext.equalsIgnoreCase("vhdx")) {
-                return ImageFormat.VHDX;
-            } else if (ext.equalsIgnoreCase("qcow2")) {
-                return ImageFormat.QCOW2;
-            } else if (ext.equalsIgnoreCase("ova")) {
-                return ImageFormat.OVA;
-            } else if (ext.equalsIgnoreCase("tar")) {
-                return ImageFormat.TAR;
-            } else if (ext.equalsIgnoreCase("img") || ext.equalsIgnoreCase("raw")) {
-                return ImageFormat.RAW;
-            } else if (ext.equalsIgnoreCase("vmdk")) {
-                return ImageFormat.VMDK;
-            } else if (ext.equalsIgnoreCase("vdi")) {
-                return ImageFormat.VDI;
-            }
-        }
-
-        return null;
-
-    }
-
-    protected Long getVirtualSize(File file, ImageFormat format) {
-        Processor processor = null;
-        try {
-            if (format == null) {
-                return file.length();
-            } else if (format == ImageFormat.QCOW2) {
-                processor = new QCOW2Processor();
-            } else if (format == ImageFormat.OVA) {
-                processor = new OVAProcessor();
-            } else if (format == ImageFormat.VHD) {
-                processor = new VhdProcessor();
-            } else if (format == ImageFormat.RAW) {
-                processor = new RawImageProcessor();
-            } else if (format == ImageFormat.VMDK) {
-                processor = new VmdkProcessor();
-            }
-
-            if (processor == null) {
-                return file.length();
-            }
-
-            processor.configure("template processor", new HashMap<String, Object>());
-            return processor.getVirtualSize(file);
-        } catch (Exception e) {
-            s_logger.debug("Failed to get virtual size:", e);
-        }
-        return file.length();
-    }
-
-    protected Answer copyFromNfsToS3(CopyCommand cmd) {
-        final DataTO srcData = cmd.getSrcTO();
-        final DataTO destData = cmd.getDestTO();
-        DataStoreTO srcDataStore = srcData.getDataStore();
-        NfsTO srcStore = (NfsTO)srcDataStore;
-        DataStoreTO destDataStore = destData.getDataStore();
-
-        final S3TO s3 = (S3TO)destDataStore;
-
-        try {
-            final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath());
-
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
-            }
-
-            final String bucket = s3.getBucketName();
-            File srcFile = _storage.getFile(templatePath);
-            // guard the case where templatePath does not have file extension, since we are not completely sure
-            // about hypervisor, so we check each extension
-            if (!srcFile.exists()) {
-                srcFile = _storage.getFile(templatePath + ".qcow2");
-                if (!srcFile.exists()) {
-                    srcFile = _storage.getFile(templatePath + ".vhd");
-                    if (!srcFile.exists()) {
-                        srcFile = _storage.getFile(templatePath + ".ova");
-                        if (!srcFile.exists()) {
-                            srcFile = _storage.getFile(templatePath + ".vmdk");
-                            if (!srcFile.exists()) {
-                                return new CopyCmdAnswer("Can't find src file:" + templatePath);
-                            }
-                        }
-                    }
-                }
-            }
-
-            long srcSize = srcFile.length();
-            ImageFormat format = getTemplateFormat(srcFile.getName());
-            String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
-            if (!s3.getSingleUpload(srcSize)) {
-                mputFile(s3, srcFile, bucket, key);
-            } else {
-                putFile(s3, srcFile, bucket, key);
-            }
-
-            DataTO retObj = null;
-            if (destData.getObjectType() == DataObjectType.TEMPLATE) {
-                TemplateObjectTO newTemplate = new TemplateObjectTO();
-                newTemplate.setPath(key);
-                newTemplate.setSize(getVirtualSize(srcFile, format));
-                newTemplate.setPhysicalSize(srcFile.length());
-                newTemplate.setFormat(format);
-                retObj = newTemplate;
-            } else if (destData.getObjectType() == DataObjectType.VOLUME) {
-                VolumeObjectTO newVol = new VolumeObjectTO();
-                newVol.setPath(key);
-                newVol.setSize(srcFile.length());
-                retObj = newVol;
-            } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
-                SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
-                newSnapshot.setPath(key);
-                retObj = newSnapshot;
-            }
-
-            return new CopyCmdAnswer(retObj);
-        } catch (Exception e) {
-            s_logger.error("failed to upload" + srcData.getPath(), e);
-            return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
-        }
-    }
-
-    String swiftDownload(SwiftTO swift, String container, String rfilename, String lFullPath) {
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
-                swift.getUserName() + " -K " + swift.getKey() + " download " + container + " " + rfilename + " -o " + lFullPath);
-        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
-        String result = command.execute(parser);
-        if (result != null) {
-            String errMsg = "swiftDownload failed  err=" + result;
-            s_logger.warn(errMsg);
-            return errMsg;
-        }
-        if (parser.getLines() != null) {
-            String[] lines = parser.getLines().split("\\n");
-            for (String line : lines) {
-                if (line.contains("Errno") || line.contains("failed")) {
-                    String errMsg = "swiftDownload failed , err=" + parser.getLines();
-                    s_logger.warn(errMsg);
-                    return errMsg;
-                }
-            }
-        }
-        return null;
-
-    }
-
-    String swiftDownloadContainer(SwiftTO swift, String container, String ldir) {
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("cd " + ldir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
-                swift.getUserName() + " -K " + swift.getKey() + " download " + container);
-        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
-        String result = command.execute(parser);
-        if (result != null) {
-            String errMsg = "swiftDownloadContainer failed  err=" + result;
-            s_logger.warn(errMsg);
-            return errMsg;
-        }
-        if (parser.getLines() != null) {
-            String[] lines = parser.getLines().split("\\n");
-            for (String line : lines) {
-                if (line.contains("Errno") || line.contains("failed")) {
-                    String errMsg = "swiftDownloadContainer failed , err=" + parser.getLines();
-                    s_logger.warn(errMsg);
-                    return errMsg;
-                }
-            }
-        }
-        return null;
-
-    }
-
-    String swiftUpload(SwiftTO swift, String container, String lDir, String lFilename) {
-        long SWIFT_MAX_SIZE = 5L * 1024L * 1024L * 1024L;
-        List<String> files = new ArrayList<String>();
-        if (lFilename.equals("*")) {
-            File dir = new File(lDir);
-            for (String file : dir.list()) {
-                if (file.startsWith(".")) {
-                    continue;
-                }
-                files.add(file);
-            }
-        } else {
-            files.add(lFilename);
-        }
-
-        for (String file : files) {
-            File f = new File(lDir + "/" + file);
-            long size = f.length();
-            Script command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            if (size <= SWIFT_MAX_SIZE) {
-                command.add("cd " + lDir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " +
-                        swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " upload " + container + " " + file);
-            } else {
-                command.add("cd " + lDir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " +
-                        swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " upload -S " + SWIFT_MAX_SIZE + " " + container + " " + file);
-            }
-            OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
-            String result = command.execute(parser);
-            if (result != null) {
-                String errMsg = "swiftUpload failed , err=" + result;
-                s_logger.warn(errMsg);
-                return errMsg;
-            }
-            if (parser.getLines() != null) {
-                String[] lines = parser.getLines().split("\\n");
-                for (String line : lines) {
-                    if (line.contains("Errno") || line.contains("failed")) {
-                        String errMsg = "swiftUpload failed , err=" + parser.getLines();
-                        s_logger.warn(errMsg);
-                        return errMsg;
-                    }
-                }
-            }
-        }
-
-        return null;
-    }
-
-    String[] swiftList(SwiftTO swift, String container, String rFilename) {
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
-                swift.getUserName() + " -K " + swift.getKey() + " list " + container + " " + rFilename);
-        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
-        String result = command.execute(parser);
-        if (result == null && parser.getLines() != null) {
-            String[] lines = parser.getLines().split("\\n");
-            return lines;
-        } else {
-            if (result != null) {
-                String errMsg = "swiftList failed , err=" + result;
-                s_logger.warn(errMsg);
-            } else {
-                String errMsg = "swiftList failed, no lines returns";
-                s_logger.warn(errMsg);
-            }
-        }
-        return null;
-    }
-
-    String swiftDelete(SwiftTO swift, String container, String object) {
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" +
-                swift.getUserName() + " -K " + swift.getKey() + " delete " + container + " " + object);
-        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
-        String result = command.execute(parser);
-        if (result != null) {
-            String errMsg = "swiftDelete failed , err=" + result;
-            s_logger.warn(errMsg);
-            return errMsg;
-        }
-        if (parser.getLines() != null) {
-            String[] lines = parser.getLines().split("\\n");
-            for (String line : lines) {
-                if (line.contains("Errno") || line.contains("failed")) {
-                    String errMsg = "swiftDelete failed , err=" + parser.getLines();
-                    s_logger.warn(errMsg);
-                    return errMsg;
-                }
-            }
-        }
-        return null;
-    }
-
-    public Answer execute(DeleteSnapshotsDirCommand cmd) {
-        DataStoreTO dstore = cmd.getDataStore();
-        if (dstore instanceof NfsTO) {
-            NfsTO nfs = (NfsTO)dstore;
-            String relativeSnapshotPath = cmd.getDirectory();
-            String parent = getRootDir(nfs.getUrl());
-
-            if (relativeSnapshotPath.startsWith(File.separator)) {
-                relativeSnapshotPath = relativeSnapshotPath.substring(1);
-            }
-
-            if (!parent.endsWith(File.separator)) {
-                parent += File.separator;
-            }
-            String absoluteSnapshotPath = parent + relativeSnapshotPath;
-            File snapshotDir = new File(absoluteSnapshotPath);
-            String details = null;
-            if (!snapshotDir.exists()) {
-                details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
-                s_logger.debug(details);
-                return new Answer(cmd, true, details);
-            }
-            // delete all files in the directory
-            String lPath = absoluteSnapshotPath + "/*";
-            String result = deleteLocalFile(lPath);
-            if (result != null) {
-                String errMsg = "failed to delete all snapshots " + lPath + " , err=" + result;
-                s_logger.warn(errMsg);
-                return new Answer(cmd, false, errMsg);
-            }
-            // delete the directory
-            if (!snapshotDir.delete()) {
-                details = "Unable to delete directory " + snapshotDir.getName() + " under snapshot path " + relativeSnapshotPath;
-                s_logger.debug(details);
-                return new Answer(cmd, false, details);
-            }
-            return new Answer(cmd, true, null);
-        } else if (dstore instanceof S3TO) {
-            final S3TO s3 = (S3TO)dstore;
-            final String path = cmd.getDirectory();
-            final String bucket = s3.getBucketName();
-            try {
-                S3Utils.deleteDirectory(s3, bucket, path);
-                return new Answer(cmd, true, String.format("Deleted snapshot %1%s from bucket %2$s.", path, bucket));
-            } catch (Exception e) {
-                final String errorMessage =
-                        String.format("Failed to delete snapshot %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
-                s_logger.error(errorMessage, e);
-                return new Answer(cmd, false, errorMessage);
-            }
-        } else if (dstore instanceof SwiftTO) {
-            String path = cmd.getDirectory();
-            String volumeId = StringUtils.substringAfterLast(path, "/"); // assuming
-            // that
-            // the
-            // filename
-            // is
-            // the
-            // last
-            // section
-            // in
-            // the
-            // path
-            String result = swiftDelete((SwiftTO)dstore, "V-" + volumeId.toString(), "");
-            if (result != null) {
-                String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result;
-                s_logger.warn(errMsg);
-                return new Answer(cmd, false, errMsg);
-            }
-            return new Answer(cmd, true, "Deleted snapshot " + path + " from swift");
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
-        }
-    }
-
-    private Answer execute(ComputeChecksumCommand cmd) {
-
-        String relativeTemplatePath = cmd.getTemplatePath();
-        DataStoreTO store = cmd.getStore();
-        if (!(store instanceof NfsTO)) {
-            return new Answer(cmd, false, "can't handle non nfs data store");
-        }
-        NfsTO nfsStore = (NfsTO)store;
-        String parent = getRootDir(nfsStore.getUrl());
-
-        if (relativeTemplatePath.startsWith(File.separator)) {
-            relativeTemplatePath = relativeTemplatePath.substring(1);
-        }
-
-        if (!parent.endsWith(File.separator)) {
-            parent += File.separator;
-        }
-        String absoluteTemplatePath = parent + relativeTemplatePath;
-        MessageDigest digest;
-        String checksum = null;
-        File f = new File(absoluteTemplatePath);
-        InputStream is = null;
-        byte[] buffer = new byte[8192];
-        int read = 0;
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("parent path " + parent + " relative template path " + relativeTemplatePath);
-        }
-
-        try {
-            digest = MessageDigest.getInstance("MD5");
-            is = new FileInputStream(f);
-            while ((read = is.read(buffer)) > 0) {
-                digest.update(buffer, 0, read);
-            }
-            byte[] md5sum = digest.digest();
-            BigInteger bigInt = new BigInteger(1, md5sum);
-            checksum = bigInt.toString(16);
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Successfully calculated checksum for file " + absoluteTemplatePath + " - " + checksum);
-            }
-
-        } catch (IOException e) {
-            String logMsg = "Unable to process file for MD5 - " + absoluteTemplatePath;
-            s_logger.error(logMsg);
-            return new Answer(cmd, false, checksum);
-        } catch (NoSuchAlgorithmException e) {
-            return new Answer(cmd, false, checksum);
-        } finally {
-            try {
-                if (is != null) {
-                    is.close();
-                }
-            } catch (IOException e) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Could not close the file " + absoluteTemplatePath);
-                }
-                return new Answer(cmd, false, checksum);
-            }
-        }
-
-        return new Answer(cmd, true, checksum);
-    }
-
-    private void configCerts(KeystoreManager.Certificates certs) {
-        if (certs == null) {
-            configureSSL();
-        } else {
-            String prvKey = certs.getPrivKey();
-            String pubCert = certs.getPrivCert();
-
-            try {
-                File prvKeyFile = File.createTempFile("prvkey", null);
-                String prvkeyPath = prvKeyFile.getAbsolutePath();
-                BufferedWriter out = new BufferedWriter(new FileWriter(prvKeyFile));
-                out.write(prvKey);
-                out.close();
-
-                File pubCertFile = File.createTempFile("pubcert", null);
-                String pubCertFilePath = pubCertFile.getAbsolutePath();
-
-                out = new BufferedWriter(new FileWriter(pubCertFile));
-                out.write(pubCert);
-                out.close();
-
-                configureSSL(prvkeyPath, pubCertFilePath, null);
-
-                prvKeyFile.delete();
-                pubCertFile.delete();
-
-            } catch (IOException e) {
-                s_logger.debug("Failed to config ssl: " + e.toString());
-            }
-        }
-    }
-
-    private Answer execute(SecStorageSetupCommand cmd) {
-        if (!_inSystemVM) {
-            return new Answer(cmd, true, null);
-        }
-        DataStoreTO dStore = cmd.getDataStore();
-        if (dStore instanceof NfsTO) {
-            String secUrl = cmd.getSecUrl();
-            try {
-                URI uri = new URI(secUrl);
-                String nfsHostIp = getUriHostIp(uri);
-
-                addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
-                String dir = mountUri(uri);
-
-                configCerts(cmd.getCerts());
-
-                nfsIps.add(nfsHostIp);
-                return new SecStorageSetupAnswer(dir);
-            } catch (Exception e) {
-                String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
-                s_logger.error(msg);
-                return new Answer(cmd, false, msg);
-
-            }
-        } else {
-            // TODO: what do we need to setup for S3/Swift, maybe need to mount
-            // to some cache storage
-            return new Answer(cmd, true, null);
-        }
-    }
-
-    protected Answer deleteSnapshot(final DeleteCommand cmd) {
-        DataTO obj = cmd.getData();
-        DataStoreTO dstore = obj.getDataStore();
-        if (dstore instanceof NfsTO) {
-            NfsTO nfs = (NfsTO)dstore;
-            String parent = getRootDir(nfs.getUrl());
-            if (!parent.endsWith(File.separator)) {
-                parent += File.separator;
-            }
-            String snapshotPath = obj.getPath();
-            if (snapshotPath.startsWith(File.separator)) {
-                snapshotPath = snapshotPath.substring(1);
-            }
-            // check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of
-            // snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing
-            // and return true.
-            String fullSnapPath = parent + snapshotPath;
-            File snapDir = new File(fullSnapPath);
-            if (snapDir.exists() && snapDir.isDirectory()) {
-                s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete");
-                return new Answer(cmd, true, null);
-            }
-            // passed snapshot path is a snapshot file path, then get snapshot directory first
-            int index = snapshotPath.lastIndexOf("/");
-            String snapshotName = snapshotPath.substring(index + 1);
-            snapshotPath = snapshotPath.substring(0, index);
-            String absoluteSnapshotPath = parent + snapshotPath;
-            // check if snapshot directory exists
-            File snapshotDir = new File(absoluteSnapshotPath);
-            String details = null;
-            if (!snapshotDir.exists()) {
-                details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
-                s_logger.debug(details);
-                return new Answer(cmd, false, details);
-            }
-            // delete snapshot in the directory if exists
-            String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
-            String result = deleteLocalFile(lPath);
-            if (result != null) {
-                details = "failed to delete snapshot " + lPath + " , err=" + result;
-                s_logger.warn(details);
-                return new Answer(cmd, false, details);
-            }
-            return new Answer(cmd, true, null);
-        } else if (dstore instanceof S3TO) {
-            final S3TO s3 = (S3TO)dstore;
-            final String path = obj.getPath();
-            final String bucket = s3.getBucketName();
-            try {
-                S3Utils.deleteObject(s3, bucket, path);
-                return new Answer(cmd, true, String.format("Deleted snapshot %1%s from bucket %2$s.", path, bucket));
-            } catch (Exception e) {
-                final String errorMessage =
-                        String.format("Failed to delete snapshot %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
-                s_logger.error(errorMessage, e);
-                return new Answer(cmd, false, errorMessage);
-            }
-        } else if (dstore instanceof SwiftTO) {
-            SwiftTO swiftTO = (SwiftTO)dstore;
-            String path = obj.getPath();
-            SwiftUtil.deleteObject(swiftTO, path);
-
-            return new Answer(cmd, true, "Deleted snapshot " + path + " from swift");
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
-        }
-
-    }
-
-    Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
-        String[] containers = SwiftUtil.list(swift, "", null);
-        if (containers == null) {
-            return null;
-        }
-        Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
-        for (String container : containers) {
-            if (container.startsWith("T-")) {
-                String[] files = SwiftUtil.list(swift, container, "template.properties");
-                if (files.length != 1) {
-                    continue;
-                }
-                try {
-                    File tempFile = File.createTempFile("template", ".tmp");
-                    File tmpFile = SwiftUtil.getObject(swift, tempFile, container + File.separator + "template.properties");
-                    if (tmpFile == null) {
-                        continue;
-                    }
-                    FileReader fr = new FileReader(tmpFile);
-                    BufferedReader brf = new BufferedReader(fr);
-                    String line = null;
-                    String uniqName = null;
-                    Long size = null;
-                    String name = null;
-                    while ((line = brf.readLine()) != null) {
-                        if (line.startsWith("uniquename=")) {
-                            uniqName = line.split("=")[1];
-                        } else if (line.startsWith("size=")) {
-                            size = Long.parseLong(line.split("=")[1]);
-                        } else if (line.startsWith("filename=")) {
-                            name = line.split("=")[1];
-                        }
-                    }
-                    brf.close();
-                    tempFile.delete();
-                    if (uniqName != null) {
-                        TemplateProp prop = new TemplateProp(uniqName, container + File.separator + name, size, size, true, false);
-                        tmpltInfos.put(uniqName, prop);
-                    }
-
-                } catch (IOException e) {
-                    s_logger.debug("Failed to create templ file:" + e.toString());
-                    continue;
-                } catch (Exception e) {
-                    s_logger.debug("Failed to get properties: " + e.toString());
-                    continue;
-                }
-            }
-        }
-        return tmpltInfos;
-
-    }
-
-    Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
-        String bucket = s3.getBucketName();
-        // List the objects in the source directory on S3
-        final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, TEMPLATE_ROOT_DIR);
-        if (objectSummaries == null) {
-            return null;
-        }
-        Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
-        for (S3ObjectSummary objectSummary : objectSummaries) {
-            String key = objectSummary.getKey();
-            // String installPath = StringUtils.substringBeforeLast(key,
-            // S3Utils.SEPARATOR);
-            String uniqueName = determineS3TemplateNameFromKey(key);
-            // TODO: isPublic value, where to get?
-            TemplateProp tInfo = new TemplateProp(uniqueName, key, objectSummary.getSize(), objectSummary.getSize(), true, false);
-            tmpltInfos.put(uniqueName, tInfo);
-        }
-        return tmpltInfos;
-
-    }
-
-    Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
-        String bucket = s3.getBucketName();
-        // List the objects in the source directory on S3
-        final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, VOLUME_ROOT_DIR);
-        if (objectSummaries == null) {
-            return null;
-        }
-        Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
-        for (S3ObjectSummary objectSummary : objectSummaries) {
-            String key = objectSummary.getKey();
-            // String installPath = StringUtils.substringBeforeLast(key,
-            // S3Utils.SEPARATOR);
-            Long id = determineS3VolumeIdFromKey(key);
-            // TODO: how to get volume template name
-            TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false);
-            tmpltInfos.put(id, tInfo);
-        }
-        return tmpltInfos;
-
-    }
-
-    private Answer execute(ListTemplateCommand cmd) {
-        if (!_inSystemVM) {
-            return new ListTemplateAnswer(null, null);
-        }
-
-        DataStoreTO store = cmd.getDataStore();
-        if (store instanceof NfsTO) {
-            NfsTO nfs = (NfsTO)store;
-            String secUrl = nfs.getUrl();
-            String root = getRootDir(secUrl);
-            Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
-            return new ListTemplateAnswer(secUrl, templateInfos);
-        } else if (store instanceof SwiftTO) {
-            SwiftTO swift = (SwiftTO)store;
-            Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
-            return new ListTemplateAnswer(swift.toString(), templateInfos);
-        } else if (store instanceof S3TO) {
-            S3TO s3 = (S3TO)store;
-            Map<String, TemplateProp> templateInfos = s3ListTemplate(s3);
-            return new ListTemplateAnswer(s3.getBucketName(), templateInfos);
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + store);
-        }
-    }
-
-    private Answer execute(ListVolumeCommand cmd) {
-        if (!_inSystemVM) {
-            return new ListVolumeAnswer(cmd.getSecUrl(), null);
-        }
-        DataStoreTO store = cmd.getDataStore();
-        if (store instanceof NfsTO) {
-            String root = getRootDir(cmd.getSecUrl());
-            Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
-            return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
-        } else if (store instanceof S3TO) {
-            S3TO s3 = (S3TO)store;
-            Map<Long, TemplateProp> templateInfos = s3ListVolume(s3);
-            return new ListVolumeAnswer(s3.getBucketName(), templateInfos);
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + store);
-        }
-
-    }
-
-    private Answer execute(SecStorageVMSetupCommand cmd) {
-        if (!_inSystemVM) {
-            return new Answer(cmd, true, null);
-        }
-        boolean success = true;
-        StringBuilder result = new StringBuilder();
-        for (String cidr : cmd.getAllowedInternalSites()) {
-            if (nfsIps.contains(cidr)) {
-                /*
-                 * if the internal download ip is the same with secondary
-                 * storage ip, adding internal sites will flush ip route to nfs
-                 * through storage ip.
-                 */
-                continue;
-            }
-            String tmpresult = allowOutgoingOnPrivate(cidr);
-            if (tmpresult != null) {
-                result.append(", ").append(tmpresult);
-                success = false;
-            }
-        }
-        if (success) {
-            if (cmd.getCopyPassword() != null && cmd.getCopyUserName() != null) {
-                String tmpresult = configureAuth(cmd.getCopyUserName(), cmd.getCopyPassword());
-                if (tmpresult != null) {
-                    result.append("Failed to configure auth for copy ").append(tmpresult);
-                    success = false;
-                }
-            }
-        }
-        return new Answer(cmd, success, result.toString());
-
-    }
-
-    private String deleteLocalFile(String fullPath) {
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("rm -f " + fullPath);
-        String result = command.execute();
-        if (result != null) {
-            String errMsg = "Failed to delete file " + fullPath + ", err=" + result;
-            s_logger.warn(errMsg);
-            return errMsg;
-        }
-        return null;
-    }
-
-    public String allowOutgoingOnPrivate(String destCidr) {
-        if (!_inSystemVM) {
-            return null;
-        }
-        Script command = new Script("/bin/bash", s_logger);
-        String intf = "eth1";
-        command.add("-c");
-        command.add("iptables -I OUTPUT -o " + intf + " -d " + destCidr + " -p tcp -m state --state NEW -m tcp  -j ACCEPT");
-
-        String result = command.execute();
-        if (result != null) {
-            s_logger.warn("Error in allowing outgoing to " + destCidr + ", err=" + result);
-            return "Error in allowing outgoing to " + destCidr + ", err=" + result;
-        }
-
-        addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, destCidr);
-
-        return null;
-    }
-
-    private Answer execute(SecStorageFirewallCfgCommand cmd) {
-        if (!_inSystemVM) {
-            return new Answer(cmd, true, null);
-        }
-
-        List<String> ipList = new ArrayList<String>();
-
-        for (PortConfig pCfg : cmd.getPortConfigs()) {
-            if (pCfg.isAdd()) {
-                ipList.add(pCfg.getSourceIp());
-            }
-        }
-        boolean success = true;
-        String result;
-        result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
-        if (result != null) {
-            success = false;
-        }
-
-        return new Answer(cmd, success, result);
-    }
-
-    protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
-        DataStoreTO store = cmd.getStore();
-        if (store instanceof S3TO || store instanceof SwiftTO) {
-            long infinity = Integer.MAX_VALUE;
-            return new GetStorageStatsAnswer(cmd, infinity, 0L);
-        }
-
-        String rootDir = getRootDir(((NfsTO)store).getUrl());
-        final long usedSize = getUsedSize(rootDir);
-        final long totalSize = getTotalSize(rootDir);
-        if (usedSize == -1 || totalSize == -1) {
-            return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
-        } else {
-            return new GetStorageStatsAnswer(cmd, totalSize, usedSize);
-        }
-    }
-
-    protected Answer execute(final DeleteCommand cmd) {
-        DataTO obj = cmd.getData();
-        DataObjectType objType = obj.getObjectType();
-        if (obj.getPath() == null) {
-            // account for those fake entries for NFS migration to object store
-            return new Answer(cmd, true, "Object with null install path does not exist on image store , no need to delete");
-        }
-        switch (objType) {
-        case TEMPLATE:
-            return deleteTemplate(cmd);
-        case VOLUME:
-            return deleteVolume(cmd);
-        case SNAPSHOT:
-            return deleteSnapshot(cmd);
-        }
-        return Answer.createUnsupportedCommandAnswer(cmd);
-    }
-
-    protected Answer deleteTemplate(DeleteCommand cmd) {
-        DataTO obj = cmd.getData();
-        DataStoreTO dstore = obj.getDataStore();
-        if (dstore instanceof NfsTO) {
-            NfsTO nfs = (NfsTO)dstore;
-            String relativeTemplatePath = obj.getPath();
-            String parent = getRootDir(nfs.getUrl());
-
-            if (relativeTemplatePath.startsWith(File.separator)) {
-                relativeTemplatePath = relativeTemplatePath.substring(1);
-            }
-
-            if (!parent.endsWith(File.separator)) {
-                parent += File.separator;
-            }
-            String absoluteTemplatePath = parent + relativeTemplatePath;
-            File tmpltPath = new File(absoluteTemplatePath);
-            File tmpltParent = null;
-            if(tmpltPath.exists() && tmpltPath.isDirectory()) {
-                tmpltParent = tmpltPath;
-            } else {
-                tmpltParent = tmpltPath.getParentFile();
-            }
-
-            String details = null;
-            if (!tmpltParent.exists()) {
-                details = "template parent directory " + tmpltParent.getName() + " doesn't exist";
-                s_logger.debug(details);
-                return new Answer(cmd, true, details);
-            }
-            File[] tmpltFiles = tmpltParent.listFiles();
-            if (tmpltFiles == null || tmpltFiles.length == 0) {
-                details = "No files under template parent directory " + tmpltParent.getName();
-                s_logger.debug(details);
-            } else {
-                boolean found = false;
-                for (File f : tmpltFiles) {
-                    if (!found && f.getName().equals("template.properties")) {
-                        found = true;
-                    }
-
-                    // KVM HA monitor makes a mess in the templates with its
-                    // heartbeat tests
-                    // Don't let this stop us from cleaning up the template
-                    if (f.isDirectory() && f.getName().equals("KVMHA")) {
-                        s_logger.debug("Deleting KVMHA directory contents from template location");
-                        File[] haFiles = f.listFiles();
-                        for (File haFile : haFiles) {
-                            haFile.delete();
-                        }
-                    }
-
-                    if (!f.delete()) {
-                        return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Template path " + relativeTemplatePath);
-                    }
-                }
-
-                if (!found) {
-                    details = "Can not find template.properties under " + tmpltParent.getName();
-                    s_logger.debug(details);
-                }
-            }
-            if (!tmpltParent.delete()) {
-                details = "Unable to delete directory " + tmpltParent.getName() + " under Template path " + relativeTemplatePath;
-                s_logger.debug(details);
-                return new Answer(cmd, false, details);
-            }
-            return new Answer(cmd, true, null);
-        } else if (dstore instanceof S3TO) {
-            final S3TO s3 = (S3TO)dstore;
-            final String path = obj.getPath();
-            final String bucket = s3.getBucketName();
-            try {
-                S3Utils.deleteDirectory(s3, bucket, path);
-                return new Answer(cmd, true, String.format("Deleted template %1$s from bucket %2$s.", path, bucket));
-            } catch (Exception e) {
-                final String errorMessage =
-                        String.format("Failed to delete template %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
-                s_logger.error(errorMessage, e);
-                return new Answer(cmd, false, errorMessage);
-            }
-        } else if (dstore instanceof SwiftTO) {
-            SwiftTO swift = (SwiftTO)dstore;
-            String container = "T-" + obj.getId();
-            String object = "";
-
-            try {
-                String result = swiftDelete(swift, container, object);
-                if (result != null) {
-                    String errMsg = "failed to delete object " + container + "/" + object + " , err=" + result;
-                    s_logger.warn(errMsg);
-                    return new Answer(cmd, false, errMsg);
-                }
-                return new Answer(cmd, true, "success");
-            } catch (Exception e) {
-                String errMsg = cmd + " Command failed due to " + e.toString();
-                s_logger.warn(errMsg, e);
-                return new Answer(cmd, false, errMsg);
-            }
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
-        }
-    }
-
-    protected Answer deleteVolume(final DeleteCommand cmd) {
-        DataTO obj = cmd.getData();
-        DataStoreTO dstore = obj.getDataStore();
-        if (dstore instanceof NfsTO) {
-            NfsTO nfs = (NfsTO)dstore;
-            String relativeVolumePath = obj.getPath();
-            String parent = getRootDir(nfs.getUrl());
-
-            if (relativeVolumePath.startsWith(File.separator)) {
-                relativeVolumePath = relativeVolumePath.substring(1);
-            }
-
-            if (!parent.endsWith(File.separator)) {
-                parent += File.separator;
-            }
-            String absoluteVolumePath = parent + relativeVolumePath;
-            File volPath = new File(absoluteVolumePath);
-            File tmpltParent = null;
-            if (volPath.exists() && volPath.isDirectory()) {
-                // for vmware, absoluteVolumePath represents a directory where volume files are located.
-                tmpltParent = volPath;
-            } else {
-                // for other hypervisors, the volume .vhd or .qcow2 file path is passed
-                tmpltParent = new File(absoluteVolumePath).getParentFile();
-            }
-            String details = null;
-            if (!tmpltParent.exists()) {
-                details = "volume parent directory " + tmpltParent.getName() + " doesn't exist";
-                s_logger.debug(details);
-                return new Answer(cmd, true, details);
-            }
-            File[] tmpltFiles = tmpltParent.listFiles();
-            if (tmpltFiles == null || tmpltFiles.length == 0) {
-                details = "No files under volume parent directory " + tmpltParent.getName();
-                s_logger.debug(details);
-            } else {
-                boolean found = false;
-                for (File f : tmpltFiles) {
-                    if (!found && f.getName().equals("volume.properties")) {
-                        found = true;
-                    }
-
-                    // KVM HA monitor makes a mess in the templates with its
-                    // heartbeat tests
-                    // Don't let this stop us from cleaning up the template
-                    if (f.isDirectory() && f.getName().equals("KVMHA")) {
-                        s_logger.debug("Deleting KVMHA directory contents from template location");
-                        File[] haFiles = f.listFiles();
-                        for (File haFile : haFiles) {
-                            haFile.delete();
-                        }
-                    }
-
-                    if (!f.delete()) {
-                        return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Volume path " + tmpltParent.getPath());
-                    }
-                }
-                if (!found) {
-                    details = "Can not find volume.properties under " + tmpltParent.getName();
-                    s_logger.debug(details);
-                }
-            }
-            if (!tmpltParent.delete()) {
-                details = "Unable to delete directory " + tmpltParent.getName() + " under Volume path " + tmpltParent.getPath();
-                s_logger.debug(details);
-                return new Answer(cmd, false, details);
-            }
-            return new Answer(cmd, true, null);
-        } else if (dstore instanceof S3TO) {
-            final S3TO s3 = (S3TO)dstore;
-            final String path = obj.getPath();
-            final String bucket = s3.getBucketName();
-            try {
-                S3Utils.deleteDirectory(s3, bucket, path);
-                return new Answer(cmd, true, String.format("Deleted volume %1%s from bucket %2$s.", path, bucket));
-            } catch (Exception e) {
-                final String errorMessage = String.format("Failed to delete volume %1$s from bucket %2$s due to the following error: %3$s", path, bucket, e.getMessage());
-                s_logger.error(errorMessage, e);
-                return new Answer(cmd, false, errorMessage);
-            }
-        } else if (dstore instanceof SwiftTO) {
-            Long volumeId = obj.getId();
-            String path = obj.getPath();
-            String filename = StringUtils.substringAfterLast(path, "/"); // assuming
-            // that
-            // the
-            // filename
-            // is
-            // the
-            // last
-            // section
-            // in
-            // the
-            // path
-            String result = swiftDelete((SwiftTO)dstore, "V-" + volumeId.toString(), filename);
-            if (result != null) {
-                String errMsg = "failed to delete volume " + filename + " , err=" + result;
-                s_logger.warn(errMsg);
-                return new Answer(cmd, false, errMsg);
-            }
-            return new Answer(cmd, true, "Deleted volume " + path + " from swift");
-        } else {
-            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
-        }
-
-    }
-
-    @Override
-    synchronized public String getRootDir(String secUrl) {
-        if (!_inSystemVM) {
-            return _parent;
-        }
-        try {
-            URI uri = new URI(secUrl);
-            String dir = mountUri(uri);
-            return _parent + "/" + dir;
-        } catch (Exception e) {
-            String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
-            s_logger.error(msg, e);
-            throw new CloudRuntimeException(msg);
-        }
-    }
-
-    protected long getUsedSize(String rootDir) {
-        return _storage.getUsedSpace(rootDir);
-    }
-
-    protected long getTotalSize(String rootDir) {
-        return _storage.getTotalSpace(rootDir);
-    }
-
-    protected long convertFilesystemSize(final String size) {
-        if (size == null || size.isEmpty()) {
-            return -1;
-        }
-
-        long multiplier = 1;
-        if (size.endsWith("T")) {
-            multiplier = 1024l * 1024l * 1024l * 1024l;
-        } else if (size.endsWith("G")) {
-            multiplier = 1024l * 1024l * 1024l;
-        } else if (size.endsWith("M")) {
-            multiplier = 1024l * 1024l;
-        } else {
-            assert (false) : "Well, I have no idea what this is: " + size;
-        }
-
-        return (long)(Double.parseDouble(size.substring(0, size.length() - 1)) * multiplier);
-    }
-
-    @Override
-    public Type getType() {
-        if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) {
-            return Host.Type.SecondaryStorage;
-        }
-
-        return Host.Type.SecondaryStorageCmdExecutor;
-    }
-
-    @Override
-    public PingCommand getCurrentStatus(final long id) {
-        return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        _eth1ip = (String)params.get("eth1ip");
-        _eth1mask = (String)params.get("eth1mask");
-        if (_eth1ip != null) { // can only happen inside service vm
-            params.put("private.network.device", "eth1");
-        } else {
-            s_logger.warn("eth1ip parameter has not been configured, assuming that we are not inside a system vm");
-        }
-        String eth2ip = (String)params.get("eth2ip");
-        if (eth2ip != null) {
-            params.put("public.network.device", "eth2");
-        }
-        _publicIp = (String)params.get("eth2ip");
-        _hostname = (String)params.get("name");
-
-        String inSystemVM = (String)params.get("secondary.storage.vm");
-        if (inSystemVM == null || "true".equalsIgnoreCase(inSystemVM)) {
-            s_logger.debug("conf secondary.storage.vm is true, act as if executing in SSVM");
-            _inSystemVM = true;
-        }
-
-        _storageIp = (String)params.get("storageip");
-        if (_storageIp == null && _inSystemVM) {
-            s_logger.warn("There is no storageip in /proc/cmdline, something wrong!");
-        }
-        _storageNetmask = (String)params.get("storagenetmask");
-        _storageGateway = (String)params.get("storagegateway");
-        super.configure(name, params);
-
-        _params = params;
-        String value = (String)params.get("scripts.timeout");
-        _timeout = NumbersUtil.parseInt(value, 1440) * 1000;
-
-        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
-        configureStorageLayerClass(params);
-
-        if (_inSystemVM) {
-            _storage.mkdirs(_parent);
-        }
-
-        _configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh");
-        if (_configSslScr != null) {
-            s_logger.info("config_ssl.sh found in " + _configSslScr);
-        }
-
-        _configAuthScr = Script.findScript(getDefaultScriptsDir(), "config_auth.sh");
-        if (_configSslScr != null) {
-            s_logger.info("config_auth.sh found in " + _configAuthScr);
-        }
-
-        _configIpFirewallScr = Script.findScript(getDefaultScriptsDir(), "ipfirewall.sh");
-        if (_configIpFirewallScr != null) {
-            s_logger.info("_configIpFirewallScr found in " + _configIpFirewallScr);
-        }
-
-        createTemplateFromSnapshotXenScript = Script.findScript(getDefaultScriptsDir(), "create_privatetemplate_from_snapshot_xen.sh");
-        if (createTemplateFromSnapshotXenScript == null) {
-            throw new ConfigurationException("create_privatetemplate_from_snapshot_xen.sh not found in " + getDefaultScriptsDir());
-        }
-
-        _role = (String)params.get("role");
-        if (_role == null) {
-            _role = SecondaryStorageVm.Role.templateProcessor.toString();
-        }
-        s_logger.info("Secondary storage runs in role " + _role);
-
-        _guid = (String)params.get("guid");
-        if (_guid == null) {
-            throw new ConfigurationException("Unable to find the guid");
-        }
-
-        _dc = (String)params.get("zone");
-        if (_dc == null) {
-            throw new ConfigurationException("Unable to find the zone");
-        }
-        _pod = (String)params.get("pod");
-
-        _instance = (String)params.get("instance");
-
-        if (!_inSystemVM) {
-            _parent = (String)params.get("mount.path");
-        }
-
-        if (_inSystemVM) {
-            _localgw = (String)params.get("localgw");
-            if (_localgw != null) { // can only happen inside service vm
-                String mgmtHost = (String)params.get("host");
-                addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
-
-                String internalDns1 = (String)params.get("internaldns1");
-                if (internalDns1 == null) {
-                    s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
-                } else {
-                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
-                }
-
-                String internalDns2 = (String)params.get("internaldns2");
-                if (internalDns2 != null) {
-                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
-                }
-
-            }
-
-            startAdditionalServices();
-            _params.put("install.numthreads", "50");
-            _params.put("secondary.storage.vm", "true");
-        }
-
-        try {
-            _params.put(StorageLayer.InstanceConfigKey, _storage);
-            _dlMgr = new DownloadManagerImpl();
-            _dlMgr.configure("DownloadManager", _params);
-            _upldMgr = new UploadManagerImpl();
-            _upldMgr.configure("UploadManager", params);
-        } catch (ConfigurationException e) {
-            s_logger.warn("Caught problem while configuring DownloadManager", e);
-            return false;
-        }
-        return true;
-    }
-
-    protected void configureStorageLayerClass(Map<String, Object> params) throws ConfigurationException {
-        String value;
-        if (_storage == null) {
-            value = (String)params.get(StorageLayer.ClassConfigKey);
-            if (value == null) {
-                value = "com.cloud.storage.JavaStorageLayer";
-            }
-
-            try {
-                Class<?> clazz = Class.forName(value);
-                _storage = (StorageLayer)clazz.newInstance();
-                _storage.configure("

<TRUNCATED>

[46/50] [abbrv] git commit: updated refs/heads/rbac to 3b58a45

Posted by mc...@apache.org.
CLOUDSTACK-6048: UI > Infrastructure > socket >  listing > (1) remove LXC, OVM.
(2) change XenServer label to differentiate XenServer version.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/04766c6d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/04766c6d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/04766c6d

Branch: refs/heads/rbac
Commit: 04766c6d476226192f663913cfaa911fc3ec29b2
Parents: 6212767
Author: Jessica Wang <je...@apache.org>
Authored: Thu Feb 6 16:49:03 2014 -0800
Committer: Jessica Wang <je...@apache.org>
Committed: Thu Feb 6 16:55:39 2014 -0800

----------------------------------------------------------------------
 ui/scripts/system.js | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04766c6d/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index ba5746e..7832bef 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -8464,7 +8464,7 @@
                                 	var array1 = [];
                                 	
                                 	// ***** non XenServer (begin) *****
-                                	var hypervisors = ["Hyperv", "KVM", "VMware", "BareMetal", "Ovm", "LXC"];
+                                	var hypervisors = ["Hyperv", "KVM", "VMware", "BareMetal"];
                                 	
                                         	var supportSocketHypervisors = {
                                         		"Hyperv": 1, 
@@ -8536,8 +8536,8 @@
                                 	var currentPage = 1;
                                 	var returnedHostCount = 0;
                                 	
-                                	var returnedHostCountForXenServer = 0;
-                                	var returnedHostCountForXenServer620 = 0;                                 	
+                                	var returnedHostCountForXenServer61x = 0;  //'XenServer 6.1.x and before'
+                                	var returnedHostCountForXenServer620 = 0;  //'XenServer 6.2.0'                               	
                                 	var returnedHostCpusocketsSumForXenServer620 = 0;    
                                 	
                                 	var callListHostsWithPage = function() {                                                		
@@ -8567,7 +8567,7 @@
                                         					returnedHostCpusocketsSumForXenServer620 += items[i].cpusockets;
                                         				} 
                                     				} else {
-                                    					returnedHostCountForXenServer++;
+                                    					returnedHostCountForXenServer61x++;
                                     				}
                                     			}  
                                     			
@@ -8582,8 +8582,8 @@
                                 	callListHostsWithPage();                                	                                                  	
                                 	
                                 	array1.push({
-                                        hypervisor: 'XenServer',
-                                        hosts: returnedHostCountForXenServer,
+                                        hypervisor: 'XenServer 6.1.x and before',
+                                        hosts: returnedHostCountForXenServer61x,
                                         sockets: 'N/A'                                                   
                                     });