add sample driver code: solidfire and s3

This commit is contained in:
Edison Su 2012-11-28 19:50:07 -08:00
parent fc16e1ea1a
commit ac5622cc2a
20 changed files with 486 additions and 16 deletions

View File

@ -39,6 +39,7 @@
<module>storage</module>
<module>storage/volume</module>
<module>storage/image</module>
<module>storage/imagemotion</module>
<module>storage/backup</module>
<module>storage/snapshot</module>
<module>storage/integration-test</module>

View File

@ -0,0 +1,62 @@
<!-- 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-engine-storage-imagemotion</artifactId>
<name>Apache CloudStack Engine Storage Image Motion Component</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-volume</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-image</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${cs.mysql.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
</project>

View File

@ -22,11 +22,7 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
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;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.image.ImageService;
import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;

View File

@ -38,6 +38,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-imagemotion</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>

View File

@ -66,15 +66,5 @@
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -23,7 +23,7 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
private final String providerName = "default primary data store provider";
protected PrimaryDataStoreDriver driver;
private PrimaryDataStoreProviderVO provider;
private final PrimaryDataStoreDao dataStoreDao;
protected final PrimaryDataStoreDao dataStoreDao;
protected PrimaryDataStoreLifeCycle dataStoreLifeCycle;
@Inject

View File

@ -35,6 +35,7 @@ import org.apache.cloudstack.storage.image.motion.ImageMotionService;
import org.apache.cloudstack.storage.volume.db.VolumeDao;
import org.apache.cloudstack.storage.volume.db.VolumeVO;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
@ -45,7 +46,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
//1. change volume state
//2. orchestrator of volume, control most of the information of volume, storage pool id, voluem state, scope etc.
@Service
@Component
public class VolumeServiceImpl implements VolumeService {
@Inject
VolumeDao volDao;

View File

@ -45,6 +45,8 @@
<module>user-authenticators/ldap</module>
<module>user-authenticators/md5</module>
<module>user-authenticators/plain-text</module>
<module>storage/volume/solidfire</module>
<module>storage/image/s3</module>
</modules>
<dependencies>

View File

@ -0,0 +1,41 @@
<!--
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-plugin-storage-image-s3</artifactId>
<name>Apache CloudStack Plugin - Storage Image S3</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-image</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
</project>

View File

@ -0,0 +1,40 @@
<!-- 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-plugin-storage-volume-solidfire</artifactId>
<name>Apache CloudStack Plugin - Storage Volume solidfire</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-volume</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${cs.mysql.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
</project>

View File

@ -0,0 +1,40 @@
package org.apache.cloudstack.storage.datastore.driver;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeObject;
public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
@Override
public boolean createVolume(VolumeObject vol) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean createVolumeFromBaseImage(VolumeObject volume,
TemplateOnPrimaryDataStoreInfo template) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deleteVolume(VolumeObject vo) {
// TODO Auto-generated method stub
return false;
}
@Override
public String grantAccess(VolumeObject vol, EndPoint ep) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean revokeAccess(VolumeObject vol, EndPoint ep) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -0,0 +1,43 @@
package org.apache.cloudstack.storage.datastore.provider;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.driver.SolidfirePrimaryDataStoreDriver;
import org.springframework.stereotype.Component;
import com.cloud.utils.component.ComponentInject;
@Component
public class SolidfirePrimaryDataStoreProvider extends
DefaultPrimaryDatastoreProviderImpl {
private final String name = "Solidfre Primary Data Store Provider";
private SolidfirePrimaryDataStoreDriver driver;
@Inject
public SolidfirePrimaryDataStoreProvider(PrimaryDataStoreDao dataStoreDao) {
super(dataStoreDao);
driver = new SolidfirePrimaryDataStoreDriver();
// TODO Auto-generated constructor stub
}
@Override
public String getName() {
return name;
}
@Override
public PrimaryDataStore getDataStore(long dataStoreId) {
PrimaryDataStoreVO dsv = dataStoreDao.findById(dataStoreId);
if (dsv == null) {
return null;
}
PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null);
pds = ComponentInject.inject(pds);
return pds;
}
}

View File

@ -0,0 +1,18 @@
package org.apache.cloudstack.storage.test;
import org.aspectj.lang.ProceedingJoinPoint;
import com.cloud.utils.db.Transaction;
public class AopTestAdvice {
public Object AopTestMethod(ProceedingJoinPoint call) throws Throwable {
Transaction txn = Transaction.open(call.getSignature().getName());
Object ret = null;
try {
ret = call.proceed();
} finally {
txn.close();
}
return ret;
}
}

View File

@ -0,0 +1,35 @@
package org.apache.cloudstack.storage.test;
import org.apache.cloudstack.storage.image.motion.ImageMotionService;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import com.cloud.agent.AgentManager;
import com.cloud.host.dao.HostDao;
public class ChildTestConfiguration extends TestConfiguration {
@Override
@Bean
public HostDao hostDao() {
HostDao dao = super.hostDao();
HostDao nDao = Mockito.spy(dao);
return nDao;
}
@Bean
public AgentManager agentMgr() {
return Mockito.mock(AgentManager.class);
}
@Bean
public ImageMotionService imageMotion() {
return Mockito.mock(ImageMotionService.class);
}
/* @Override
@Bean
public PrimaryDataStoreDao primaryDataStoreDao() {
return Mockito.mock(PrimaryDataStoreDaoImpl.class);
}*/
}

View File

@ -0,0 +1,21 @@
package org.apache.cloudstack.storage.test;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDaoImpl;
@Configuration
public class TestConfiguration {
@Bean
public HostDao hostDao() {
return new HostDaoImpl();
}
@Bean
public PrimaryDataStoreDao primaryDataStoreDao() {
return new PrimaryDataStoreDaoImpl();
}
}

View File

@ -0,0 +1,140 @@
package org.apache.cloudstack.storage.test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.agent.AgentManager;
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 VolumeTest {
@Inject
HostDao hostDao;
@Inject
HostPodDao podDao;
@Inject
ClusterDao clusterDao;
@Inject
DataCenterDao dcDao;
@Inject
PrimaryDataStoreDao primaryStoreDao;
@Inject
PrimaryDataStoreProviderManager primaryDataStoreProviderMgr;
@Inject
AgentManager agentMgr;
Long dcId;
Long clusterId;
@Before
public void setUp() {
//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
HostVO host = new HostVO(UUID.randomUUID().toString());
host.setName("devcloud xen host");
host.setType(Host.Type.Routing);
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);
List<HostVO> results = new ArrayList<HostVO>();
results.add(host);
Mockito.when(hostDao.listAll()).thenReturn(results);
Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
CreateVolumeAnswer createVolumeFromImageAnswer = new CreateVolumeAnswer(UUID.randomUUID().toString());
try {
Mockito.when(agentMgr.send(Mockito.anyLong(), Mockito.any(CreateVolumeFromBaseImageCommand.class))).thenReturn(createVolumeFromImageAnswer);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Mockito.when(primaryStoreDao.findById(Mockito.anyLong())).thenReturn(primaryStore);
}
private PrimaryDataStoreInfo createPrimaryDataStore() {
try {
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("Solidfre Primary Data Store Provider");
PrimaryDataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
Map<String, String> params = new HashMap<String, String>();
params.put("url", "nfs://test/test");
params.put("dcId", dcId.toString());
params.put("clusterId", clusterId.toString());
params.put("name", "my primary data store");
PrimaryDataStoreInfo primaryDataStoreInfo = lifeCycle.registerDataStore(params);
return primaryDataStoreInfo;
} catch (ConfigurationException e) {
return null;
}
}
@Test
public void createPrimaryDataStoreTest() {
createPrimaryDataStore();
}
}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<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:tx="http://www.springframework.org/schema/tx" 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/tx
http://www.springframework.org/schema/tx/spring-tx-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">
<context:annotation-config />
<context:component-scan base-package="org.apache.cloudstack.storage" />
<context:component-scan base-package="org.apache.cloudstack.engine.subsystem.api.storage" />
<context:component-scan base-package="com.cloud.utils.db" />
<context:component-scan base-package="com.cloud.utils.component" />
<context:component-scan base-package="com.cloud.host.dao" />
<context:component-scan base-package="com.cloud.dc.dao" />
<context:component-scan base-package=" com.cloud.upgrade.dao" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="aopTestBean" class="org.apache.cloudstack.storage.test.AopTestAdvice"/>
<aop:config proxy-target-class="true" >
<aop:aspect id="AopTestAdvice" ref="aopTestBean">
<aop:pointcut id="aoptest"
expression="@annotation(com.cloud.utils.db.DB)" />
<aop:around pointcut-ref="aoptest" method="AopTestMethod"/>
</aop:aspect>
</aop:config>
<bean class="org.apache.cloudstack.storage.test.ChildTestConfiguration" />
</beans>