add more implementation in volume project

This commit is contained in:
Edison Su 2012-12-03 18:34:40 -08:00
parent d836b14a64
commit 2c689adce7
20 changed files with 402 additions and 111 deletions

View File

@ -76,11 +76,11 @@ public interface VolumeEntity extends CloudStackEntity {
long getSize();
String getTemplatePath();
String getTemplateUuid();
VolumeDiskType getDiskType();
VolumeType getType();
StorageEntity getDataStore();
void setPath(String path);
boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template);
}

View File

@ -33,4 +33,5 @@ public interface PrimaryDataStoreInfo {
public long getAvailableCapacity();
public List<EndPoint> getEndPoints();
public long getId();
public String getUuid();
}

View File

@ -38,5 +38,7 @@ public interface VolumeInfo {
public long getId();
public Volume.State getCurrentState();
public Volume.State getDesiredState();
public Date getCreatedData();
public Date getCreatedDate();
public Date getUpdatedDate();
public String getOwner();
}

View File

@ -44,7 +44,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
@ -293,7 +293,7 @@ public class volumeServiceTest {
DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class);
//assertNotNull(provider.dataStoreDao);
DefaultPrimaryDataStoreImpl dpdsi = new DefaultPrimaryDataStoreImpl(null, null, null);
DefaultPrimaryDataStore dpdsi = new DefaultPrimaryDataStore(null, null, null);
ComponentInject.inject(dpdsi);
//assertNotNull(dpdsi.volumeDao);
}

View File

@ -65,6 +65,5 @@
<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.
*/
package org.apache.cloudstack.storage.command;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import com.cloud.agent.api.Command;
public class DeleteVolume extends Command {
public DeleteVolume(VolumeInfo volume) {
}
protected DeleteVolume() {
}
@Override
public boolean executeInSequence() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -32,7 +32,7 @@ public interface PrimaryDataStore extends PrimaryDataStoreInfo {
List<VolumeInfo> getVolumes();
boolean deleteVolume(long id);
boolean deleteVolume(VolumeInfo volume);
VolumeInfo createVolume(VolumeInfo vo, VolumeDiskType diskType);
@ -40,8 +40,6 @@ public interface PrimaryDataStore extends PrimaryDataStoreInfo {
List<EndPoint> getEndPoints();
PrimaryDataStoreInfo getDataStoreInfo();
boolean exists(VolumeInfo vi);
boolean templateExists(TemplateInfo template);

View File

@ -0,0 +1,252 @@
/*
* 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.datastore;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import com.cloud.storage.StoragePoolStatus;
import com.cloud.storage.Storage.StoragePoolType;
public class PrimaryDataStoreEntityImpl implements StorageEntity {
private PrimaryDataStoreInfo dataStore;
public PrimaryDataStoreEntityImpl(PrimaryDataStoreInfo dataStore) {
this.dataStore = dataStore;
}
@Override
public boolean enable() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean disable() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deactivate() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean reactivate() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getUuid() {
return this.dataStore.getUuid();
}
@Override
public long getId() {
return this.dataStore.getId();
}
@Override
public String getCurrentState() {
return null;
}
@Override
public String getDesiredState() {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getCreatedTime() {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getLastUpdatedTime() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getOwner() {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<String, String> getDetails(String source) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> getDetailSources() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addDetail(String source, String name, String value) {
// TODO Auto-generated method stub
}
@Override
public void delDetail(String source, String name, String value) {
// TODO Auto-generated method stub
}
@Override
public void updateDetail(String source, String name, String value) {
// TODO Auto-generated method stub
}
@Override
public List<Method> getApplicableActions() {
// TODO Auto-generated method stub
return null;
}
@Override
public State getState() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public StoragePoolType getPoolType() {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getCreated() {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getUpdateTime() {
// TODO Auto-generated method stub
return null;
}
@Override
public long getDataCenterId() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getCapacityBytes() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getAvailableBytes() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Long getClusterId() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getHostAddress() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getPath() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getUserInfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isShared() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isLocal() {
// TODO Auto-generated method stub
return false;
}
@Override
public StoragePoolStatus getStatus() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getPort() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Long getPodId() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getStorageProvider() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getStorageType() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -30,6 +30,7 @@ import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreEntityImpl;
import org.apache.cloudstack.storage.image.TemplateEntityImpl;
import org.apache.cloudstack.storage.image.TemplateInfo;
@ -45,10 +46,6 @@ public class VolumeEntityImpl implements VolumeEntity {
return volumeInfo;
}
public void setVolumeInfo(VolumeInfo vi) {
this.volumeInfo = vi;
}
@Override
public String getUuid() {
return volumeInfo.getUuid();
@ -76,19 +73,17 @@ public class VolumeEntityImpl implements VolumeEntity {
@Override
public Date getCreatedTime() {
return volumeInfo.getCreatedData();
return volumeInfo.getCreatedDate();
}
@Override
public Date getLastUpdatedTime() {
// TODO Auto-generated method stub
return null;
return volumeInfo.getUpdatedDate();
}
@Override
public String getOwner() {
// TODO Auto-generated method stub
return null;
return volumeInfo.getOwner();
}
@Override
@ -171,50 +166,27 @@ public class VolumeEntityImpl implements VolumeEntity {
@Override
public void destroy() {
// TODO Auto-generated method stub
vs.deleteVolume(volumeInfo);
}
@Override
public long getSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getTemplatePath() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTemplateUuid() {
// TODO Auto-generated method stub
return null;
return volumeInfo.getSize();
}
@Override
public VolumeDiskType getDiskType() {
// TODO Auto-generated method stub
return null;
return volumeInfo.getDiskType();
}
@Override
public VolumeType getType() {
// TODO Auto-generated method stub
return null;
return volumeInfo.getType();
}
@Override
public StorageEntity getDataStore() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setPath(String path) {
// TODO Auto-generated method stub
return new PrimaryDataStoreEntityImpl(volumeInfo.getDataStore());
}
@Override

View File

@ -18,7 +18,6 @@
*/
package org.apache.cloudstack.storage.volume;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@ -48,7 +47,7 @@ public interface VolumeService {
* @return
* @throws ConcurrentOperationException
*/
boolean deleteVolume(long volumeId);
boolean deleteVolume(VolumeInfo volume);
/**
*

View File

@ -77,4 +77,6 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId);
VolumeVO findByVolumeIdAndPoolId(long volumeId, long poolId);
}

View File

@ -46,6 +46,8 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.UpdateBuilder;
import com.cloud.utils.exception.CloudRuntimeException;
@ -426,4 +428,12 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
vol = this.persist(vol);
return vol;
}
@Override
public VolumeVO findByVolumeIdAndPoolId(long volumeId, long poolId) {
SearchCriteriaService<VolumeVO, VolumeVO> sc = SearchCriteria2.create(VolumeVO.class);
sc.addAnd(sc.getEntity().getId(), Op.EQ, volumeId);
sc.addAnd(sc.getEntity().getPoolId(), Op.EQ, poolId);
return sc.find();
}
}

View File

@ -27,8 +27,8 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.component.ComponentInject;
import edu.emory.mathcs.backport.java.util.Collections;
public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreImpl.class);
public class DefaultPrimaryDataStore implements PrimaryDataStore {
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStore.class);
protected PrimaryDataStoreDriver driver;
protected PrimaryDataStoreVO pdsv;
protected PrimaryDataStoreInfo pdsInfo;
@ -39,11 +39,16 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Inject
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
private DefaultPrimaryDataStore(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
this.driver = driver;
this.pdsv = pdsv;
this.pdsInfo = pdsInfo;
}
public static DefaultPrimaryDataStore createDataStore(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
DefaultPrimaryDataStore dataStore = new DefaultPrimaryDataStore(driver, pdsv, pdsInfo);
return ComponentInject.inject(dataStore);
}
@Override
public VolumeInfo getVolume(long id) {
@ -54,14 +59,17 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Override
public List<VolumeInfo> getVolumes() {
// TODO Auto-generated method stub
return null;
List<VolumeVO> volumes = volumeDao.findByPoolId(this.getId());
List<VolumeInfo> volumeInfos = new ArrayList<VolumeInfo>();
for (VolumeVO volume : volumes) {
volumeInfos.add(VolumeObject.getVolumeObject(this, volume));
}
return volumeInfos;
}
@Override
public boolean deleteVolume(long id) {
// TODO Auto-generated method stub
return false;
public boolean deleteVolume(VolumeInfo volume) {
return this.driver.deleteVolume((VolumeObject)volume);
}
@Override
@ -81,12 +89,6 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
return endpoints;
}
@Override
public PrimaryDataStoreInfo getDataStoreInfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isHypervisorSupported(HypervisorType hypervisor) {
// TODO Auto-generated method stub
@ -107,14 +109,12 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Override
public long getCapacity() {
// TODO Auto-generated method stub
return 0;
return this.driver.getCapacity();
}
@Override
public long getAvailableCapacity() {
// TODO Auto-generated method stub
return 0;
return this.driver.getAvailableCapacity();
}
@Override
@ -130,8 +130,8 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Override
public boolean exists(VolumeInfo vi) {
// TODO Auto-generated method stub
return false;
VolumeVO vol = volumeDao.findByVolumeIdAndPoolId(vi.getId(), this.getId());
return (vol != null) ? true : false;
}
@Override

View File

@ -2,12 +2,12 @@ package org.apache.cloudstack.storage.datastore.driver;
import java.util.List;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeCommand;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.command.DeleteVolume;
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
import org.apache.cloudstack.storage.to.VolumeTO;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
@ -28,34 +28,22 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
// The default driver will send createvolume command to one of hosts
// which can access its datastore
List<EndPoint> endPoints = vol.getDataStore().getEndPoints();
int retries = 3;
VolumeInfo volInfo = vol;
CreateVolumeCommand createCmd = new CreateVolumeCommand(new VolumeTO(volInfo));
Answer answer = null;
int i = 0;
boolean result = false;
Answer answer = sendOutCommand(createCmd, endPoints);
for (EndPoint ep : endPoints) {
answer = ep.sendMessage(createCmd);
if (answer == null) {
if (i < retries) {
s_logger.debug("create volume failed, retrying: " + i);
}
i++;
} else {
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
vol.setPath(volAnswer.getVolumeUuid());
result = true;
}
}
return result;
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
vol.setPath(volAnswer.getVolumeUuid());
return true;
}
@Override
public boolean deleteVolume(VolumeObject vo) {
// TODO Auto-generated method stub
return false;
DeleteVolume cmd = new DeleteVolume((VolumeInfo)vo);
List<EndPoint> endPoints = vo.getDataStore().getEndPoints();
sendOutCommand(cmd, endPoints);
return true;
}
@Override
@ -67,7 +55,7 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
@Override
public boolean revokeAccess(VolumeObject vol, EndPoint ep) {
// TODO Auto-generated method stub
return false;
return true;
}
protected Answer sendOutCommand(Command cmd, List<EndPoint> endPoints) {
@ -85,6 +73,15 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
break;
}
}
if (answer == null || answer.getDetails() != null) {
if (answer == null) {
throw new CloudRuntimeException("Failed to created volume");
} else {
throw new CloudRuntimeException(answer.getDetails());
}
}
return answer;
}
@ -97,16 +94,20 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
Answer answer = sendOutCommand(cmd, endPoints);
if (answer == null || answer.getDetails() != null) {
if (answer == null) {
throw new CloudRuntimeException("Failed to created volume");
} else {
throw new CloudRuntimeException(answer.getDetails());
}
} else {
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
volume.setPath(volAnswer.getVolumeUuid());
return true;
}
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
volume.setPath(volAnswer.getVolumeUuid());
return true;
}
@Override
public long getCapacity() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getAvailableCapacity() {
// TODO Auto-generated method stub
return 0;
}
}

View File

@ -14,4 +14,8 @@ public interface PrimaryDataStoreDriver {
String grantAccess(VolumeObject vol, EndPoint ep);
boolean revokeAccess(VolumeObject vol, EndPoint ep);
long getCapacity();
long getAvailableCapacity();
}

View File

@ -5,7 +5,7 @@ import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
@ -40,8 +40,7 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
return null;
}
PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null);
pds = ComponentInject.inject(pds);
PrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(driver, dsv, null);
return pds;
}

View File

@ -68,7 +68,7 @@ public class VolumeObject implements VolumeInfo {
}
public PrimaryDataStoreInfo getDataStoreInfo() {
return dataStore.getDataStoreInfo();
return dataStore;
}
public Volume.State getState() {
@ -136,7 +136,7 @@ public class VolumeObject implements VolumeInfo {
}
@Override
public Date getCreatedData() {
public Date getCreatedDate() {
// TODO Auto-generated method stub
return null;
}

View File

@ -83,7 +83,7 @@ public class VolumeServiceImpl implements VolumeService {
@DB
@Override
public boolean deleteVolume(long volumeId) {
public boolean deleteVolume(VolumeInfo volumeId) {
return true;
}

View File

@ -37,4 +37,16 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
return false;
}
@Override
public long getCapacity() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getAvailableCapacity() {
// TODO Auto-generated method stub
return 0;
}
}

View File

@ -2,7 +2,7 @@ package org.apache.cloudstack.storage.datastore.provider;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
@ -36,7 +36,7 @@ public class SolidfirePrimaryDataStoreProvider extends
return null;
}
PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null);
PrimaryDataStore pds = new DefaultPrimaryDataStore(driver, dsv, null);
pds = ComponentInject.inject(pds);
return pds;
}