cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [04/16] git commit: updated refs/heads/vmsync to f49257c
Date Sun, 19 May 2013 16:14:57 GMT
Added missing files


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

Branch: refs/heads/vmsync
Commit: 813321b42dc4288bc1ac9391cf3fe84d29490779
Parents: 9340690
Author: Alex Huang <alex.huang@gmail.com>
Authored: Thu May 16 09:50:11 2013 -0700
Committer: Alex Huang <alex.huang@gmail.com>
Committed: Thu May 16 09:50:11 2013 -0700

----------------------------------------------------------------------
 .../engine/vm/VirtualMachineEntityImpl2.java       |  283 +++++++++++
 .../engine/vm/VirtualMachineOrchestrator.java      |  387 +++++++++++++++
 .../com/cloud/agent/manager/AttacheHandler.java    |   29 ++
 .../src/com/cloud/configuration/ConfigValue.java   |   67 +++
 4 files changed, 766 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/813321b4/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineEntityImpl2.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineEntityImpl2.java
b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineEntityImpl2.java
new file mode 100644
index 0000000..614b709
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineEntityImpl2.java
@@ -0,0 +1,283 @@
+// 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.engine.vm;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.cloud.entity.VMEntityVO;
+import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.NicEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.StorageOrchestrator;
+import org.apache.cloudstack.network.NetworkOrchestrator;
+
+import com.cloud.dao.EntityManager;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.CloudException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.storage.VolumeVO;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.VirtualMachineProfile.Param;
+
+public class VirtualMachineEntityImpl2 implements VirtualMachineEntity {
+
+    private static EntityManager s_entityMgr;
+    private static VirtualMachineOrchestrator s_vmOrchestrator;
+    private static NetworkOrchestrator s_networkOrchestrator;
+    private static StorageOrchestrator s_storageOrchestrator;
+
+    private static GenericSearchBuilder<VolumeVO, String> VolumeUuidSB;
+    private static SearchBuilder<VolumeVO> VolumeSB;
+    private static GenericSearchBuilder<NicVO, String> NicUuidSB;
+    private static SearchBuilder<NicVO> NicSB;
+
+    public static void init(
+            EntityManager entityMgr,
+            VirtualMachineOrchestrator vmOrchestrator,
+            NetworkOrchestrator networkOrchestrator,
+            StorageOrchestrator storageOrchestrator) {
+        s_entityMgr = entityMgr;
+        s_vmOrchestrator = vmOrchestrator;
+        s_networkOrchestrator = networkOrchestrator;
+        s_storageOrchestrator = storageOrchestrator;
+
+        VolumeUuidSB = s_entityMgr.createGenericSearchBuilder(VolumeVO.class, String.class);
+        VolumeVO vol = VolumeUuidSB.entity();
+        VolumeUuidSB.selectField(vol.getUuid()).and("vm", vol.getInstanceId(), Op.EQ).done();
+
+        VolumeSB = s_entityMgr.createSearchBuilder(VolumeVO.class);
+        vol = VolumeSB.entity();
+        VolumeSB.and("vm", vol.getInstanceId(), Op.EQ).done();
+
+        NicUuidSB = s_entityMgr.createGenericSearchBuilder(NicVO.class, String.class);
+        NicVO nic = NicUuidSB.entity();
+        NicUuidSB.selectField(nic.getUuid()).and("vm", nic.getInstanceId(), Op.EQ).done();
+
+        NicSB = s_entityMgr.createSearchBuilder(NicVO.class);
+        nic = NicSB.entity();
+        NicSB.and("vm", nic.getInstanceId(), Op.EQ).done();
+    }
+
+    VMEntityVO _vm;
+    DeployDestination _dest;
+
+    public VirtualMachineEntityImpl2(VMEntityVO vm) {
+        _vm = vm;
+    }
+
+    @Override
+    public String getUuid() {
+        return _vm.getUuid();
+    }
+
+    @Override
+    public long getId() {
+        return _vm.getId();
+    }
+
+    @Override
+    public String getCurrentState() {
+        return _vm.getState().toString();
+    }
+
+    @Override
+    public String getDesiredState() {
+        return null;
+    }
+
+    @Override
+    public Date getCreatedTime() {
+        return _vm.getCreated();
+    }
+
+    @Override
+    public Date getLastUpdatedTime() {
+        return _vm.getUpdateTime();
+    }
+
+    @Override
+    public String getOwner() {
+        return _vm.getOwner();
+    }
+
+    @Override
+    public Map<String, String> getDetails() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void addDetail(String name, String value) {
+    }
+
+    @Override
+    public void delDetail(String name, String value) {
+    }
+
+    @Override
+    public void updateDetail(String name, String value) {
+    }
+
+    @Override
+    public List<Method> getApplicableActions() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public List<String> listVolumeIds() {
+        SearchCriteria<String> sc = VolumeUuidSB.create();
+        sc.setParameters("vm", _vm.getId());
+
+        return s_entityMgr.search(VolumeVO.class, sc);
+    }
+
+    @Override
+    public List<VolumeEntity> listVolumes() {
+        SearchCriteria<VolumeVO> sc = VolumeSB.create();
+        sc.setParameters("vm", _vm.getId());
+
+        List<VolumeVO> vols = s_entityMgr.search(VolumeVO.class, sc);
+        List<VolumeEntity> entities = new ArrayList<VolumeEntity>(vols.size());
+        for (VolumeVO vol : vols) {
+            entities.add(null);
+        }
+
+        return entities;
+    }
+
+    @Override
+    public List<String> listNicUuids() {
+        SearchCriteria<String> sc = NicUuidSB.create();
+        sc.setParameters("vm", _vm.getId());
+
+        return s_entityMgr.search(NicVO.class, sc);
+    }
+
+    @Override
+    public List<NicEntity> listNics() {
+        return null;
+    }
+
+    @Override
+    public TemplateEntity getTemplate() {
+        return null;
+    }
+
+    @Override
+    public List<String> listTags() {
+        return null;
+    }
+
+    @Override
+    public void addTag() {
+    }
+
+    @Override
+    public void delTag() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public String reserve(String plannerToUse, DeploymentPlan plan, ExcludeList exclude,
String caller)
+            throws InsufficientCapacityException, ResourceUnavailableException {
+        return null;
+    }
+
+    @Override
+    public void migrateTo(String reservationId, String caller) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void deploy(String reservationId, String caller, Map<Param, Object> params)
throws InsufficientCapacityException, ResourceUnavailableException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public boolean stop(String caller) throws ResourceUnavailableException, CloudException
{
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void cleanup() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public boolean destroy(String caller) throws AgentUnavailableException, CloudException,
ConcurrentOperationException {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public VirtualMachineEntity duplicate(String externalId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public SnapshotEntity takeSnapshotOf() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void attach(VolumeEntity volume, short deviceId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void detach(VolumeEntity volume) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void connectTo(NetworkEntity network, short nicId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void disconnectFrom(NetworkEntity netowrk, short nicId) {
+        // TODO Auto-generated method stub
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/813321b4/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
new file mode 100644
index 0000000..9cb0cb0
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
@@ -0,0 +1,387 @@
+// 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.engine.vm;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.engine.cloud.entity.VMEntityVO;
+import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl;
+import org.apache.cloudstack.engine.subsystem.api.storage.StorageOrchestrator;
+import org.apache.cloudstack.network.NetworkOrchestrator;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.Listener;
+import com.cloud.agent.api.AgentControlAnswer;
+import com.cloud.agent.api.AgentControlCommand;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.cluster.ManagementServerNode;
+import com.cloud.configuration.Config;
+import com.cloud.configuration.ConfigValue;
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.dao.EntityManager;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.ConnectionException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.user.AccountVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.concurrency.NamedThreadFactory;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.ReservationContextImpl;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.VirtualMachineProfileImpl;
+import com.cloud.vm.VmWorkJobDao;
+
+/**
+ * VirtualMachineOrchestrator orchestrates virtual machine operations.
+ *
+ */
+public class VirtualMachineOrchestrator extends ManagerBase {
+    private final static Logger s_logger = Logger.getLogger(VirtualMachineOrchestrator.class);
+    @Inject
+    EntityManager _entityMgr;
+    @Inject
+    ConfigurationManager _configMgr;
+    @Inject
+    NetworkOrchestrator _networkOrchestrator;
+    @Inject
+    StorageOrchestrator _storageOrchestrator;
+    @Inject
+    AgentManager _agentMgr;
+    @Inject
+    VmWorkJobDao _workJobDao;
+    @Inject
+    VirtualMachineManager _itMgr;
+    
+    protected ConfigValue<Integer> _retry;
+    protected ConfigValue<Long> _cancelWait;
+    protected ConfigValue<Long> _cleanupWait;
+    protected ConfigValue<Long> _cleanupInterval;
+    protected ConfigValue<Long> _opWaitInterval;
+    protected ConfigValue<Integer> _lockStateRetry;
+    protected ConfigValue<Integer> _operationTimeout;
+    protected ConfigValue<Boolean> _forceStop;
+
+    // FIXME:  Hopefully these can be temporary for now
+    @Inject
+    UserDao _userDao;
+    @Inject
+    DomainDao _domainDao;
+    @Inject
+    AccountDao _accountDao;
+    @Inject
+    ServiceOfferingDao _offeringDao;
+    @Inject
+    VMTemplateDao _templateDao;
+    // FIXME: Hopefull we can remove the above stuff.
+
+    long _nodeId;
+
+    ScheduledExecutorService _executor = null;
+
+    public VirtualMachineEntity create(
+            String id,
+            String owner,
+            String templateId,
+            String hostName,
+            String displayName,
+            String hypervisor,
+            int cpu,
+            int speed,
+            long memory,
+            Long diskSize,
+            List<String> computeTags,
+            List<String> rootDiskTags,
+            Map<String, NicProfile> networkNicMap,
+            DeploymentPlan plan) throws InsufficientCapacityException {
+
+        List<Pair<NetworkVO, NicProfile>> networkIpMap = new ArrayList<Pair<NetworkVO,
NicProfile>>();
+        for (String uuid : networkNicMap.keySet()) {
+            NetworkVO network = _entityMgr.findByUuid(NetworkVO.class, uuid);
+            if (network != null) {
+                networkIpMap.add(new Pair<NetworkVO, NicProfile>(network, networkNicMap.get(uuid)));
+            }
+        }
+
+        VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
+        vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags,
rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
+
+        HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
+
+        //load vm instance and offerings and call virtualMachineManagerImpl
+        VMInstanceVO vm = _entityMgr.findByUuid(VMInstanceVO.class, id);
+
+        // If the template represents an ISO, a disk offering must be passed in, and will
be used to create the root disk
+        // Else, a disk offering is optional, and if present will be used to create the data
disk
+
+        Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null,
null);
+        List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO,
Long>>();
+
+        ServiceOfferingVO offering = _entityMgr.findById(ServiceOfferingVO.class, vm.getServiceOfferingId());
+        rootDiskOffering.first(offering);
+
+        if (vm.getDiskOfferingId() != null) {
+            DiskOfferingVO diskOffering = _entityMgr.findById(DiskOfferingVO.class, vm.getDiskOfferingId());
+            if (diskOffering == null) {
+                throw new InvalidParameterValueException("Unable to find disk offering "
+ vm.getDiskOfferingId());
+            }
+            Long size = null;
+            if (diskOffering.getDiskSize() == 0) {
+                size = diskSize;
+                if (size == null) {
+                    throw new InvalidParameterValueException(
+                            "Disk offering " + diskOffering
+                                    + " requires size parameter.");
+                }
+            }
+            dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
+        }
+
+        if (_itMgr.allocate(_entityMgr.findById(UserVmVO.class, vm.getId()),
+                _entityMgr.findById(VMTemplateVO.class, templateId),
+                offering,
+                rootDiskOffering,
+                dataDiskOfferings,
+                networkIpMap,
+                null,
+                plan,
+                hypervisorType,
+                _entityMgr.findById(AccountVO.class, new Long(owner))) == null) {
+            return null;
+        }
+
+        return vmEntity;
+    }
+
+    public VirtualMachineEntity createFromScratch(
+            String id,
+            String owner,
+            String isoId,
+            String hostName,
+            String displayName,
+            String hypervisor,
+            String os,
+            int cpu,
+            int speed,
+            long memory,
+            Long diskSize,
+            List<String> computeTags,
+            List<String> rootDiskTags,
+            Map<String, NicProfile> networkNicMap,
+            DeploymentPlan plan) throws InsufficientCapacityException {
+
+        // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName,
displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
+        VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
+        vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags,
rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
+
+        //load vm instance and offerings and call virtualMachineManagerImpl
+        VMInstanceVO vm = _entityMgr.findByUuid(VMInstanceVO.class, id);
+
+        Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null,
null);
+        ServiceOfferingVO offering = _entityMgr.findById(ServiceOfferingVO.class, vm.getServiceOfferingId());
+        rootDiskOffering.first(offering);
+
+        List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO,
Long>>();
+        Long diskOfferingId = vm.getDiskOfferingId();
+        if (diskOfferingId == null) {
+            throw new InvalidParameterValueException("Installing from ISO requires a disk
offering to be specified for the root disk.");
+        }
+        DiskOfferingVO diskOffering = _entityMgr.findById(DiskOfferingVO.class, diskOfferingId);
+        if (diskOffering == null) {
+            throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
+        }
+        Long size = null;
+        if (diskOffering.getDiskSize() == 0) {
+            size = diskSize;
+            if (size == null) {
+                throw new InvalidParameterValueException("Disk offering " + diskOffering
+ " requires size parameter.");
+            }
+        }
+        rootDiskOffering.first(diskOffering);
+        rootDiskOffering.second(size);
+
+        List<Pair<NetworkVO, NicProfile>> networkIpMap = new ArrayList<Pair<NetworkVO,
NicProfile>>();
+        for (String uuid : networkNicMap.keySet()) {
+            NetworkVO network = _entityMgr.findByUuid(NetworkVO.class, uuid);
+            if (network != null) {
+                networkIpMap.add(new Pair<NetworkVO, NicProfile>(network, networkNicMap.get(uuid)));
+            }
+        }
+
+        HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
+
+        if (_itMgr.allocate(_entityMgr.findById(UserVmVO.class, vm.getId()),
+                _entityMgr.findById(VMTemplateVO.class, new Long(isoId)),
+                offering, rootDiskOffering, dataDiskOfferings, networkIpMap,
+                null, plan, hypervisorType,
+                _entityMgr.findById(AccountVO.class, new Long(owner))) == null) {
+            return null;
+        }
+
+        return vmEntity;
+    }
+
+    public VirtualMachineEntity get(String uuid) {
+        VMEntityVO vo = _entityMgr.findByUuid(VMEntityVO.class, uuid);
+        return new VirtualMachineEntityImpl2(vo);
+    }
+
+    public VirtualMachineEntity get(long id) {
+        VMEntityVO vo = _entityMgr.findById(VMEntityVO.class, id);
+        return new VirtualMachineEntityImpl2(vo);
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
+        super.configure(name, params);
+        
+        _retry = _configMgr.getConfig(Config.StartRetry, Integer.class);
+        
+
+        _cancelWait = _configMgr.getConfig(Config.VmOpCancelInterval, Long.class);
+        _cleanupWait = _configMgr.getConfig(Config.VmOpCleanupWait, Long.class);
+        _cleanupInterval = _configMgr.getConfig(Config.VmOpCleanupInterval, Long.class).setMultiplier(1000);
+        _opWaitInterval = _configMgr.getConfig(Config.VmOpWaitInterval, Long.class).setMultiplier(1000);
+        _lockStateRetry = _configMgr.getConfig(Config.VmOpLockStateRetry, Integer.class);
+        _operationTimeout = _configMgr.getConfig(Config.Wait, Integer.class).setMultiplier(2);
+        _forceStop = _configMgr.getConfig(Config.VmDestroyForcestop, Boolean.class);
+
+        _nodeId = ManagementServerNode.getManagementServerId();
+
+        _agentMgr.registerForHostEvents(new AgentListener(), true, true, true);
+
+        _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup"));
+
+        ReservationContextImpl.setComponents(_userDao, _domainDao, _accountDao);
+        VirtualMachineProfileImpl.setComponents(_offeringDao, _templateDao, _accountDao);
+        VirtualMachineEntityImpl2.init(_entityMgr, this, _networkOrchestrator, _storageOrchestrator);
+
+        return true;
+    }
+
+    @Override
+    public boolean start() {
+        _executor.scheduleAtFixedRate(new CleanupTask(), _cleanupInterval.value(), _cleanupInterval.value(),
TimeUnit.SECONDS);
+        return super.start();
+    }
+    
+    @Override
+    public boolean stop() {
+        _executor.shutdownNow();
+        try {
+            _executor.awaitTermination(30, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            s_logger.warn("Interrupted while waiting for executor shutdown");
+        }
+        if (!_executor.isShutdown()) {
+            s_logger.warn("Not all background tasks are shutdown.");
+        }
+        if (!_executor.isTerminated()) {
+            s_logger.warn("Not all background tasks are terminated.");
+        }
+        return super.stop();
+    }
+
+    protected class CleanupTask implements Runnable {
+
+        @Override
+        public void run() {
+            s_logger.info("VM Operation Thread Running");
+
+            try {
+                Date cutDate = DateUtil.currentGMTTime();
+                cutDate = new Date(cutDate.getTime() - 60000);
+                _workJobDao.expungeCompletedWorkJobs(cutDate);
+            } catch (Throwable e) {
+                s_logger.error("Unexpected exception", e);
+            }
+        }
+    }
+
+    private class AgentListener implements Listener {
+
+        @Override
+        public boolean processAnswers(long agentId, long seq, Answer[] answers) {
+            return false;
+        }
+
+        @Override
+        public boolean processCommands(long agentId, long seq, Command[] commands) {
+            return false;
+        }
+
+        @Override
+        public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand
cmd) {
+            return null;
+        }
+
+        @Override
+        public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance)
throws ConnectionException {
+        }
+
+        @Override
+        public boolean processDisconnect(long agentId, Status state) {
+            return false;
+        }
+
+        @Override
+        public boolean isRecurring() {
+            return false;
+        }
+
+        @Override
+        public int getTimeout() {
+            return 0;
+        }
+
+        @Override
+        public boolean processTimeout(long agentId, long seq) {
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/813321b4/server/src/com/cloud/agent/manager/AttacheHandler.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/AttacheHandler.java b/server/src/com/cloud/agent/manager/AttacheHandler.java
new file mode 100644
index 0000000..765b2c3
--- /dev/null
+++ b/server/src/com/cloud/agent/manager/AttacheHandler.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 com.cloud.agent.manager;
+
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.exception.ConnectionException;
+import com.cloud.host.HostVO;
+import com.cloud.resource.ServerResource;
+
+// FIXME!  Frank!  When can you get rid of me!
+public interface AttacheHandler {
+    public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource
resource, boolean forRebalance) throws ConnectionException;
+
+    public AgentAttache findAttache(long hostId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/813321b4/server/src/com/cloud/configuration/ConfigValue.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigValue.java b/server/src/com/cloud/configuration/ConfigValue.java
new file mode 100644
index 0000000..967944a
--- /dev/null
+++ b/server/src/com/cloud/configuration/ConfigValue.java
@@ -0,0 +1,67 @@
+// 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.configuration;
+
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+// This class returns the config value in a class.  We can later enhance this
+// class to get auto-updated by the database.
+public class ConfigValue<T> {
+
+    Config _config;
+    ConfigurationDao _dao;
+    Number _multiplier;
+
+    protected ConfigValue(ConfigurationDao dao, Config config) {
+        _dao = dao;
+        _config = config;
+        _multiplier = 1;
+    }
+
+    public Config getConfig() {
+        return _config;
+    }
+
+    public ConfigValue<T> setMultiplier(Number multiplier) {  // Convience method
+        _multiplier = multiplier;
+        return this;
+    }
+
+    @SuppressWarnings("unchecked")
+    public T value() {
+        ConfigurationVO vo = _dao.findByName(_config.key());
+        String value = vo != null ? vo.getValue() : _config.getDefaultValue();
+        
+        Class<?> type = _config.getType();
+        if (type.isAssignableFrom(Boolean.class)) {
+            return (T)Boolean.valueOf(value);
+        } else if (type.isAssignableFrom(Integer.class)) {
+            return (T)new Integer((Integer.parseInt(value) * _multiplier.intValue()));
+        } else if (type.isAssignableFrom(Long.class)) {
+            return (T)new Long(Long.parseLong(value) * _multiplier.longValue());
+        } else if (type.isAssignableFrom(Short.class)) {
+            return (T)new Short(Short.parseShort(value));
+        } else if (type.isAssignableFrom(String.class)) {
+            return (T)value;
+        } else if (type.isAssignableFrom(Float.class)) {
+            return (T)new Float(Float.parseFloat(value) * _multiplier.floatValue());
+        }
+
+        throw new CloudRuntimeException("Unsupported data type for config values: " + type);
+    }
+}


Mime
View raw message