diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java index 7c110bfe122..99956887384 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java @@ -37,4 +37,5 @@ public interface PrimaryDataStoreInfo { public String getUuid(); public State getManagedState(); public String getName(); + public String getType(); } diff --git a/engine/storage/integration-test/pom.xml b/engine/storage/integration-test/pom.xml index c2f4d24d183..947614c5588 100644 --- a/engine/storage/integration-test/pom.xml +++ b/engine/storage/integration-test/pom.xml @@ -44,6 +44,12 @@ ${project.version} test + + org.apache.cloudstack + cloud-plugin-hypervisor-xen + ${project.version} + test + mysql mysql-connector-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 9077a5a7e38..aa9abe3a671 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 @@ -18,7 +18,7 @@ public class ChildTestConfiguration extends TestConfiguration { @Bean public AgentManager agentMgr() { - return Mockito.mock(AgentManager.class); + return new DirectAgentManagerSimpleImpl(); } /* @Override @Bean diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerImpl.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java similarity index 74% rename from engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerImpl.java rename to engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java index 13454106cc0..080e65b1fee 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerImpl.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java @@ -18,10 +18,14 @@ */ package org.apache.cloudstack.storage.test; +import java.util.HashMap; import java.util.Map; +import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; + import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; import com.cloud.agent.StartupCommandProcessor; @@ -35,11 +39,16 @@ import com.cloud.exception.ConnectionException; import com.cloud.exception.OperationTimedoutException; import com.cloud.host.HostVO; import com.cloud.host.Status.Event; +import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.xen.resource.XcpOssResource; import com.cloud.resource.ServerResource; -public class DirectAgentManagerImpl implements AgentManager { - +public class DirectAgentManagerSimpleImpl implements AgentManager { + private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class); + private Map hostResourcesMap = new HashMap(); + @Inject + HostDao hostDao; @Override public boolean configure(String name, Map params) throws ConfigurationException { // TODO Auto-generated method stub @@ -70,10 +79,43 @@ public class DirectAgentManagerImpl implements AgentManager { return null; } + protected void loadResource(Long hostId) { + HostVO host = hostDao.findById(hostId); + Map params = new HashMap(); + params.put("guid", host.getGuid()); + params.put("ipaddress", host.getPrivateIpAddress()); + params.put("username", "root"); + params.put("password", "password"); + params.put("zone", String.valueOf(host.getDataCenterId())); + params.put("pod", String.valueOf(host.getPodId())); + + ServerResource resource = null; + if (host.getHypervisorType() == HypervisorType.XenServer) { + resource = new XcpOssResource(); + } + + try { + resource.configure(host.getName(), params); + hostResourcesMap.put(hostId, resource); + } catch (ConfigurationException e) { + logger.debug("Failed to load resource:" + e.toString()); + } + } + @Override - public Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException { - // TODO Auto-generated method stub - return null; + public synchronized Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException { + ServerResource resource = hostResourcesMap.get(hostId); + if (resource == null) { + loadResource(hostId); + resource = hostResourcesMap.get(hostId); + } + + if (resource == null) { + return null; + } + + Answer answer = resource.executeRequest(cmd); + return answer; } @Override diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java new file mode 100644 index 00000000000..852f3791139 --- /dev/null +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java @@ -0,0 +1,125 @@ +/* + * 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.test; + +import java.util.UUID; + +import javax.inject.Inject; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.ReadyCommand; +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.HostPodDao; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.org.Cluster.ClusterType; +import com.cloud.org.Managed.ManagedState; +import com.cloud.resource.ResourceState; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="classpath:/resource/storageContext.xml") +public class DirectAgentTest { + @Inject + AgentManager agentMgr; + @Inject + HostDao hostDao; + @Inject + HostPodDao podDao; + @Inject + ClusterDao clusterDao; + @Inject + DataCenterDao dcDao; + private long dcId; + private long clusterId; + private long hostId; + private String hostGuid = "759ee4c9-a15a-297b-67c6-ac267d8aa429"; + @Before + public void setUp() { + HostVO host = hostDao.findByGuid(hostGuid); + if (host != null) { + hostId = host.getId(); + dcId = host.getDataCenterId(); + clusterId = host.getClusterId(); + return; + } + //create data center + DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", + null, null, NetworkType.Basic, null, null, true, true); + dc = dcDao.persist(dc); + dcId = dc.getId(); + //create pod + + HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "192.168.56.1", "192.168.56.0/24", 8, "test"); + pod = podDao.persist(pod); + //create xen cluster + ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster"); + cluster.setHypervisorType(HypervisorType.XenServer.toString()); + cluster.setClusterType(ClusterType.CloudManaged); + cluster.setManagedState(ManagedState.Managed); + cluster = clusterDao.persist(cluster); + clusterId = cluster.getId(); + //create xen host + + //TODO: this hardcode host uuid in devcloud + host = new HostVO(hostGuid); + host.setName("devcloud xen host"); + host.setType(Host.Type.Routing); + host.setHypervisorType(HypervisorType.XenServer); + host.setPrivateIpAddress("192.168.56.2"); + host.setDataCenterId(dc.getId()); + host.setVersion("6.0.1"); + host.setAvailable(true); + host.setSetup(true); + host.setLastPinged(0); + host.setResourceState(ResourceState.Enabled); + host.setClusterId(cluster.getId()); + + host = hostDao.persist(host); + hostId = host.getId(); + } + + @Test + public void testInitResource() { + ReadyCommand cmd = new ReadyCommand(dcId); + try { + agentMgr.send(hostId, cmd); + } catch (AgentUnavailableException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OperationTimedoutException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java index f633dac37db..2c24739b8e6 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java @@ -293,8 +293,7 @@ public class volumeServiceTest { DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class); //assertNotNull(provider.dataStoreDao); - DefaultPrimaryDataStore dpdsi = new DefaultPrimaryDataStore(null, null, null); - ComponentInject.inject(dpdsi); + DefaultPrimaryDataStore dpdsi = DefaultPrimaryDataStore.createDataStore(null, null, null); //assertNotNull(dpdsi.volumeDao); } diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java index eca4a69231d..5763496c7e1 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java @@ -147,7 +147,6 @@ public class PrimaryDataStoreEntityImpl implements StorageEntity { @Override public StoragePoolType getPoolType() { - // TODO Auto-generated method stub return null; } diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java index 4a5922dda37..b6350ed5a38 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java @@ -5,6 +5,7 @@ import java.util.List; import javax.inject.Inject; +import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; @@ -168,4 +169,28 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore { // TODO Auto-generated method stub return true; } + + @Override + public String getUuid() { + // TODO Auto-generated method stub + return null; + } + + @Override + public State getManagedState() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getType() { + // TODO Auto-generated method stub + return null; + } } diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java index f5e2068e450..9a462d81fd3 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java @@ -140,4 +140,16 @@ public class VolumeObject implements VolumeInfo { // TODO Auto-generated method stub return null; } + + @Override + public Date getUpdatedDate() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getOwner() { + // TODO Auto-generated method stub + return null; + } } diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 13ead8eefdb..2340185bb96 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -139,7 +139,6 @@ public class VolumeServiceImpl implements VolumeService { try { dataStore.installTemplate(templateOnPrimaryStoreObj); templateOnPrimaryStoreObj.updateStatus(Status.CREATED); - } catch (Exception e) { templateOnPrimaryStoreObj.updateStatus(Status.ABANDONED); templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed);