mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
starting unit test
This commit is contained in:
parent
d62da2a7b5
commit
573d13dd7c
@ -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 org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
|
||||
|
||||
public interface PrimaryDataStore {
|
||||
VolumeEntity getVolume(String id);
|
||||
List<VolumeEntity> getVolumes();
|
||||
boolean deleteVolume(VolumeEntity id);
|
||||
VolumeEntity createVolume(String id, VolumeDiskType diskType);
|
||||
List<EndPoint> getEndPoints();
|
||||
PrimaryDataStoreInfo getDataStoreInfo();
|
||||
}
|
||||
@ -34,6 +34,7 @@ public class HypervisorHostEndPoint implements EndPoint {
|
||||
private long hostId;
|
||||
@Inject
|
||||
AgentManager agentMgr;
|
||||
|
||||
public HypervisorHostEndPoint(long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
@ -260,7 +260,6 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (needToCreateVolume) {
|
||||
createVolumeOnStorage(volume, destStore, reservationId);
|
||||
} else if (needToMigrateVolume) {
|
||||
@ -276,7 +275,6 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
|
||||
public void prepare(long vmId, DeploymentPlan plan, String reservationId) {
|
||||
VirtualMachine vm = _vmDao.findById(vmId);
|
||||
|
||||
|
||||
List<VolumeVO> vols = _volumeDao.findUsableVolumesForInstance(vm.getId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Prepare " + vols.size() + " volumes for " + vm.getInstanceName());
|
||||
@ -289,7 +287,6 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void release(long vmId, String reservationId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -338,8 +335,6 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
|
||||
_volumeDao.update(volume.getId(), volume);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType) {
|
||||
VolumeEntityImpl vei = ((VolumeEntityImpl) volume);
|
||||
|
||||
@ -5,7 +5,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.StorageProvider;
|
||||
|
||||
public interface StorageProviderManager {
|
||||
StorageProvider getProvider(String uuid);
|
||||
|
||||
StorageProvider getProvider(long poolId);
|
||||
|
||||
StorageProvider getBackupStorageProvider(long zoneId);
|
||||
|
||||
DataStore getDataStore(long poolId);
|
||||
}
|
||||
|
||||
@ -16,8 +16,7 @@ public class StorageProviderManagerImpl implements StorageProviderManager, Manag
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -20,5 +20,6 @@ package org.apache.cloudstack.storage.backup;
|
||||
|
||||
public interface BackupService {
|
||||
String grantAccessSnapshot(long snapshotId, long endpointId);
|
||||
|
||||
boolean revokeAccessSnapshot(long snapshotId, long endpointId);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import com.cloud.agent.api.Answer;
|
||||
|
||||
public class CreateVolumeAnswer extends Answer {
|
||||
private String volumeUuid;
|
||||
|
||||
protected CreateVolumeAnswer() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import com.cloud.agent.api.Command;
|
||||
|
||||
public class CreateVolumeCommand extends Command {
|
||||
protected VolumeTO volumeInfo;
|
||||
|
||||
public CreateVolumeCommand(VolumeTO volumeInfo) {
|
||||
super();
|
||||
this.volumeInfo = volumeInfo;
|
||||
|
||||
@ -26,10 +26,12 @@ import com.cloud.agent.api.Command;
|
||||
public class CreateVolumeFromBaseImageCommand extends Command {
|
||||
private VolumeTO volume;
|
||||
private ImageOnPrimayDataStoreTO image;
|
||||
|
||||
public CreateVolumeFromBaseImageCommand(VolumeTO volume, ImageOnPrimayDataStoreTO image) {
|
||||
this.volume = volume;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -19,11 +19,5 @@
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
public enum DataStoreStatus {
|
||||
Creating,
|
||||
Up,
|
||||
PrepareForMaintenance,
|
||||
ErrorInMaintenance,
|
||||
CancelMaintenance,
|
||||
Maintenance,
|
||||
Removed;
|
||||
Creating, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
|
||||
}
|
||||
|
||||
@ -38,8 +38,7 @@ public class DefaultDataStore implements DataStore {
|
||||
protected long _id;
|
||||
protected DataStoreLifeCycle _dslf;
|
||||
|
||||
public DefaultDataStore(
|
||||
) {
|
||||
public DefaultDataStore() {
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
|
||||
@ -46,6 +46,7 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
|
||||
private HostDao hostDao;
|
||||
@Inject
|
||||
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
|
||||
|
||||
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
|
||||
this.driver = driver;
|
||||
this.pdsv = pdsv;
|
||||
|
||||
@ -30,19 +30,29 @@ import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
|
||||
|
||||
public interface PrimaryDataStore extends PrimaryDataStoreInfo {
|
||||
VolumeInfo getVolume(long id);
|
||||
|
||||
List<VolumeInfo> getVolumes();
|
||||
|
||||
boolean deleteVolume(long id);
|
||||
|
||||
VolumeInfo createVolume(VolumeInfo vo, VolumeDiskType diskType);
|
||||
|
||||
VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore);
|
||||
|
||||
List<EndPoint> getEndPoints();
|
||||
|
||||
PrimaryDataStoreInfo getDataStoreInfo();
|
||||
|
||||
boolean exists(VolumeInfo vi);
|
||||
|
||||
boolean templateExists(TemplateInfo template);
|
||||
|
||||
TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template);
|
||||
|
||||
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template);
|
||||
|
||||
VolumeDiskType getDefaultDiskType();
|
||||
|
||||
}
|
||||
|
||||
@ -33,8 +33,7 @@ public class PrimaryDataStoreInfoImpl implements PrimaryDataStoreInfo {
|
||||
protected long avail;
|
||||
protected boolean localStorage;
|
||||
|
||||
public PrimaryDataStoreInfoImpl(List<HypervisorType> hypers, List<VolumeDiskType> diskTypes,
|
||||
long capacity, long avail, boolean localStorage) {
|
||||
public PrimaryDataStoreInfoImpl(List<HypervisorType> hypers, List<VolumeDiskType> diskTypes, long capacity, long avail, boolean localStorage) {
|
||||
this.avail = avail;
|
||||
this.caapcity = capacity;
|
||||
this.localStorage = localStorage;
|
||||
|
||||
@ -122,7 +122,6 @@ public class DataStoreVO implements Identity {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
public String getPoolType() {
|
||||
return protocol;
|
||||
}
|
||||
@ -175,7 +174,6 @@ public class DataStoreVO implements Identity {
|
||||
capacityBytes = capacity;
|
||||
}
|
||||
|
||||
|
||||
public Long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
@ -196,8 +194,7 @@ public class DataStoreVO implements Identity {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public void setStatus(DataStoreStatus status)
|
||||
{
|
||||
public void setStatus(DataStoreStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
@ -25,40 +25,47 @@ import org.apache.cloudstack.storage.datastore.DataStoreStatus;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
||||
public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
|
||||
|
||||
/**
|
||||
* @param datacenterId -- the id of the datacenter (availability zone)
|
||||
* @param datacenterId
|
||||
* -- the id of the datacenter (availability zone)
|
||||
*/
|
||||
List<DataStoreVO> listByDataCenterId(long datacenterId);
|
||||
|
||||
/**
|
||||
* @param datacenterId -- the id of the datacenter (availability zone)
|
||||
* @param datacenterId
|
||||
* -- the id of the datacenter (availability zone)
|
||||
*/
|
||||
List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId);
|
||||
|
||||
/**
|
||||
* Set capacity of storage pool in bytes
|
||||
* @param id pool id.
|
||||
* @param capacity capacity in bytes
|
||||
*
|
||||
* @param id
|
||||
* pool id.
|
||||
* @param capacity
|
||||
* capacity in bytes
|
||||
*/
|
||||
void updateCapacity(long id, long capacity);
|
||||
|
||||
/**
|
||||
* Set available bytes of storage pool in bytes
|
||||
* @param id pool id.
|
||||
* @param available available capacity in bytes
|
||||
*
|
||||
* @param id
|
||||
* pool id.
|
||||
* @param available
|
||||
* available capacity in bytes
|
||||
*/
|
||||
void updateAvailable(long id, long available);
|
||||
|
||||
|
||||
DataStoreVO persist(DataStoreVO pool, Map<String, String> details);
|
||||
|
||||
/**
|
||||
* Find pool by name.
|
||||
*
|
||||
* @param name name of pool.
|
||||
* @param name
|
||||
* name of pool.
|
||||
* @return the single StoragePoolVO
|
||||
*/
|
||||
List<DataStoreVO> findPoolByName(String name);
|
||||
@ -66,8 +73,10 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
|
||||
/**
|
||||
* Find pools by the pod that matches the details.
|
||||
*
|
||||
* @param podId pod id to find the pools in.
|
||||
* @param details details to match. All must match for the pool to be returned.
|
||||
* @param podId
|
||||
* pod id to find the pools in.
|
||||
* @param details
|
||||
* details to match. All must match for the pool to be returned.
|
||||
* @return List of StoragePoolVO
|
||||
*/
|
||||
List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
|
||||
@ -77,7 +86,8 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
|
||||
/**
|
||||
* Find pool by UUID.
|
||||
*
|
||||
* @param uuid uuid of pool.
|
||||
* @param uuid
|
||||
* uuid of pool.
|
||||
* @return the single StoragePoolVO
|
||||
*/
|
||||
DataStoreVO findPoolByUUID(String uuid);
|
||||
|
||||
@ -34,6 +34,7 @@ import org.springframework.stereotype.Component;
|
||||
import com.cloud.storage.StoragePoolDetailVO;
|
||||
import com.cloud.storage.dao.StoragePoolDetailsDao;
|
||||
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
@ -53,9 +54,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
protected final SearchBuilder<DataStoreVO> DeleteLvmSearch;
|
||||
protected final GenericSearchBuilder<DataStoreVO, Long> StatusCountSearch;
|
||||
|
||||
|
||||
|
||||
protected final StoragePoolDetailsDao _detailsDao;
|
||||
protected final PrimaryDataStoreDetailsDao _detailsDao = null;
|
||||
|
||||
private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
|
||||
private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
|
||||
@ -97,14 +96,12 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
DeleteLvmSearch.cp();
|
||||
DeleteLvmSearch.done();
|
||||
|
||||
|
||||
|
||||
StatusCountSearch = createSearchBuilder(Long.class);
|
||||
StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
|
||||
StatusCountSearch.select(null, Func.COUNT, null);
|
||||
StatusCountSearch.done();
|
||||
|
||||
_detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class);
|
||||
// _detailsDao = ComponentInject.inject(PrimaryDataStoreDetailsDaoImpl.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,7 +111,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DataStoreVO findPoolByUUID(String uuid) {
|
||||
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
|
||||
@ -122,8 +118,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
|
||||
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
|
||||
@ -131,7 +125,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DataStoreVO> listByDataCenterId(long datacenterId) {
|
||||
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
|
||||
@ -139,7 +132,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateAvailable(long id, long available) {
|
||||
DataStoreVO pool = createForUpdate(id);
|
||||
@ -147,7 +139,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
update(id, pool);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateCapacity(long id, long capacity) {
|
||||
DataStoreVO pool = createForUpdate(id);
|
||||
@ -216,22 +207,22 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
public DataStoreVO listById(Integer id)
|
||||
{
|
||||
public DataStoreVO listById(Integer id) {
|
||||
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
|
||||
sc.setParameters("id", id);
|
||||
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public DataStoreVO persist(DataStoreVO pool, Map<String, String> details) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
pool = super.persist(pool);
|
||||
if (details != null) {
|
||||
for (Map.Entry<String, String> detail : details.entrySet()) {
|
||||
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue());
|
||||
PrimaryDataStoreDetailVO vo = new PrimaryDataStoreDetailVO(pool.getId(), detail.getKey(), detail.getValue());
|
||||
_detailsDao.persist(vo);
|
||||
}
|
||||
}
|
||||
@ -297,9 +288,9 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
List<DataStoreVO> filteredStoragePools = new ArrayList<DataStoreVO>(storagePools);
|
||||
for (DataStoreVO pool : storagePools) {
|
||||
/*
|
||||
if (shared != pool.isShared()) {
|
||||
filteredStoragePools.remove(pool);
|
||||
}*/
|
||||
* if (shared != pool.isShared()) {
|
||||
* filteredStoragePools.remove(pool); }
|
||||
*/
|
||||
}
|
||||
|
||||
return filteredStoragePools;
|
||||
@ -351,8 +342,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long countPoolsByStatus(DataStoreStatus... statuses) {
|
||||
SearchCriteria<Long> sc = StatusCountSearch.create();
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
// 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.db;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="storage_pool_details")
|
||||
public class PrimaryDataStoreDetailVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
long id;
|
||||
|
||||
@Column(name="pool_id")
|
||||
long poolId;
|
||||
|
||||
@Column(name="name")
|
||||
String name;
|
||||
|
||||
@Column(name="value")
|
||||
String value;
|
||||
|
||||
public PrimaryDataStoreDetailVO(long poolId, String name, String value) {
|
||||
this.poolId = poolId;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getPoolId() {
|
||||
return poolId;
|
||||
}
|
||||
|
||||
public void setPoolId(long poolId) {
|
||||
this.poolId = poolId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected PrimaryDataStoreDetailVO() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
// 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.db;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.storage.StoragePoolDetailVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface PrimaryDataStoreDetailsDao extends GenericDao<PrimaryDataStoreDetailVO, Long> {
|
||||
|
||||
void update(long poolId, Map<String, String> details);
|
||||
Map<String, String> getDetails(long poolId);
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
// 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.db;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
public class PrimaryDataStoreDetailsDaoImpl extends GenericDaoBase<PrimaryDataStoreDetailVO, Long> implements PrimaryDataStoreDetailsDao {
|
||||
|
||||
protected final SearchBuilder<PrimaryDataStoreDetailVO> PoolSearch = null;
|
||||
|
||||
protected PrimaryDataStoreDetailsDaoImpl() {
|
||||
/*
|
||||
super();
|
||||
PoolSearch = createSearchBuilder();
|
||||
PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
|
||||
PoolSearch.done();
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(long poolId, Map<String, String> details) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
|
||||
sc.setParameters("pool", poolId);
|
||||
|
||||
txn.start();
|
||||
expunge(sc);
|
||||
for (Map.Entry<String, String> entry : details.entrySet()) {
|
||||
PrimaryDataStoreDetailVO detail = new PrimaryDataStoreDetailVO(poolId, entry.getKey(), entry.getValue());
|
||||
persist(detail);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(long poolId) {
|
||||
SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
|
||||
sc.setParameters("pool", poolId);
|
||||
|
||||
List<PrimaryDataStoreDetailVO> details = listBy(sc);
|
||||
Map<String, String> detailsMap = new HashMap<String, String>();
|
||||
for (PrimaryDataStoreDetailVO detail : details) {
|
||||
detailsMap.put(detail.getName(), detail.getValue());
|
||||
}
|
||||
|
||||
return detailsMap;
|
||||
}
|
||||
}
|
||||
@ -20,12 +20,13 @@ import com.cloud.agent.api.Command;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class DefaultPrimaryDataStoreDriverImpl implements
|
||||
PrimaryDataStoreDriver {
|
||||
public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
|
||||
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class);
|
||||
|
||||
@Override
|
||||
public boolean createVolume(VolumeObject vol) {
|
||||
//The default driver will send createvolume command to one of hosts which can access its datastore
|
||||
// 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;
|
||||
|
||||
@ -4,11 +4,14 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
|
||||
|
||||
public interface PrimaryDataStoreDriver {
|
||||
boolean createVolume(VolumeObject vol);
|
||||
|
||||
boolean createVolumeFromBaseImage(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template);
|
||||
|
||||
boolean deleteVolume(VolumeObject vo);
|
||||
|
||||
String grantAccess(VolumeObject vol, EndPoint ep);
|
||||
|
||||
boolean revokeAccess(VolumeObject vol, EndPoint ep);
|
||||
}
|
||||
|
||||
@ -22,10 +22,16 @@ import java.util.Map;
|
||||
|
||||
public interface PrimaryDataStoreLifeCycle {
|
||||
public boolean registerDataStore(Map<String, String> dsInfos);
|
||||
|
||||
public boolean attach(long scope);
|
||||
|
||||
public boolean dettach(long dataStoreId);
|
||||
|
||||
public boolean unmanaged(long dataStoreId);
|
||||
|
||||
public boolean maintain(long dataStoreId);
|
||||
|
||||
public boolean cancelMaintain(long dataStoreId);
|
||||
|
||||
public boolean deleteDataStore(long dataStoreId);
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManag
|
||||
PrimaryDataStoreProviderManager providerManager;
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
|
||||
DataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
|
||||
|
||||
@ -23,5 +23,6 @@ import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCyc
|
||||
|
||||
public interface PrimaryDataStoreManager {
|
||||
public PrimaryDataStore getPrimaryDataStore(long dataStoreId);
|
||||
|
||||
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId);
|
||||
}
|
||||
|
||||
@ -14,8 +14,7 @@ import org.springframework.stereotype.Component;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
|
||||
@Component
|
||||
public class DefaultPrimaryDatastoreProviderImpl implements
|
||||
PrimaryDataStoreProvider {
|
||||
public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
|
||||
protected PrimaryDataStoreDriver driver;
|
||||
@Inject
|
||||
public PrimaryDataStoreDao dataStoreDao;
|
||||
@ -23,6 +22,7 @@ public class DefaultPrimaryDatastoreProviderImpl implements
|
||||
public DefaultPrimaryDatastoreProviderImpl() {
|
||||
this.driver = new DefaultPrimaryDataStoreDriverImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore(long dataStoreId) {
|
||||
DataStoreVO dsv = dataStoreDao.findById(dataStoreId);
|
||||
|
||||
@ -3,9 +3,8 @@ package org.apache.cloudstack.storage.datastore.provider;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
|
||||
|
||||
|
||||
public interface PrimaryDataStoreProvider {
|
||||
public PrimaryDataStore getDataStore(long dataStoreId);
|
||||
|
||||
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
|
||||
public interface PrimaryDataStoreProviderManager {
|
||||
public PrimaryDataStoreProvider getDataStoreProvider(Long providerId);
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class ISCSI extends BaseType implements DataStoreType {
|
||||
private final String type = "iscsi";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class NetworkFileSystem extends BaseType implements DataStoreType {
|
||||
private final String type = "nfs";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.cloudstack.storage.BaseType;
|
||||
|
||||
public class SharedMount extends BaseType implements DataStoreType {
|
||||
private final String type = "SharedMountPoint";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -40,8 +40,7 @@ public abstract class AbstractStorageDriver implements DataStoreDriver {
|
||||
}
|
||||
|
||||
public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) {
|
||||
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(),
|
||||
0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait());
|
||||
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(), 0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait());
|
||||
dcmd.setSecondaryStorageUrl(tp.getImageStorageUri());
|
||||
dcmd.setPrimaryStorageUrl(_ds.getURI());
|
||||
PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer) ep.sendCommand(dcmd);
|
||||
@ -52,8 +51,7 @@ public abstract class AbstractStorageDriver implements DataStoreDriver {
|
||||
|
||||
public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep, boolean freshDownload) {
|
||||
|
||||
DownloadCommand dcmd =
|
||||
new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes());
|
||||
DownloadCommand dcmd = new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes());
|
||||
dcmd.setProxy(_ts.getHttpProxy());
|
||||
if (!freshDownload) {
|
||||
dcmd = new DownloadProgressCommand(dcmd, tp.getJobId(), RequestType.GET_OR_RESTART);
|
||||
@ -63,14 +61,13 @@ public abstract class AbstractStorageDriver implements DataStoreDriver {
|
||||
return tp;
|
||||
}
|
||||
/*
|
||||
public VolumeProfile createVolumeFromTemplate(VolumeProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep) {
|
||||
CreateCommand cmd = new CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO());
|
||||
CreateAnswer ans = (CreateAnswer)ep.sendCommand(cmd);
|
||||
VolumeTO created = ans.getVolume();
|
||||
DiskProfile diskProfile = new VolumeProfile(volProfile);
|
||||
diskProfile.setPath(created.getPath());
|
||||
diskProfile.setSize(created.getSize());
|
||||
return diskProfile;
|
||||
return null;
|
||||
}*/
|
||||
* public VolumeProfile createVolumeFromTemplate(VolumeProfile volProfile,
|
||||
* TemplateProfile tp, DataStoreEndPoint ep) { CreateCommand cmd = new
|
||||
* CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO()); CreateAnswer
|
||||
* ans = (CreateAnswer)ep.sendCommand(cmd); VolumeTO created =
|
||||
* ans.getVolume(); DiskProfile diskProfile = new VolumeProfile(volProfile);
|
||||
* diskProfile.setPath(created.getPath());
|
||||
* diskProfile.setSize(created.getSize()); return diskProfile; return null;
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
@ -26,9 +26,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeProfile;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
|
||||
public class XenServerStorageDriver extends AbstractStorageDriver {
|
||||
protected DataStore _ds;
|
||||
|
||||
public XenServerStorageDriver(DataStore ds) {
|
||||
super(ds);
|
||||
_ds = ds;
|
||||
|
||||
@ -21,12 +21,12 @@ package org.apache.cloudstack.storage.image;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile;
|
||||
|
||||
|
||||
import com.cloud.api.commands.RegisterTemplateCmd;
|
||||
|
||||
|
||||
public interface ImageManager {
|
||||
TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds);
|
||||
|
||||
TemplateProfile getProfile(long templateId);
|
||||
|
||||
TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd);
|
||||
}
|
||||
|
||||
@ -106,11 +106,9 @@ public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
protected TemplateProfile persistTemplate(TemplateProfile profile) {
|
||||
Long zoneId = profile.getZoneId();
|
||||
VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(),
|
||||
profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(),
|
||||
profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(),
|
||||
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
|
||||
profile.getDetails(), profile.getSshKeyEnabled());
|
||||
VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), profile.getFeatured(), profile.getIsExtractable(),
|
||||
TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(),
|
||||
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), profile.getDetails(), profile.getSshKeyEnabled());
|
||||
|
||||
if (zoneId == null || zoneId.longValue() == -1) {
|
||||
List<DataCenterVO> dcs = _dcDao.listAll();
|
||||
|
||||
@ -20,7 +20,10 @@ package org.apache.cloudstack.storage.image;
|
||||
|
||||
public interface ImageOrchestrator {
|
||||
void registerTemplate(long templateId);
|
||||
|
||||
void registerSnapshot(long snapshotId);
|
||||
|
||||
void registerVolume(long volumeId);
|
||||
|
||||
void registerIso(long isoId);
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ public class ImageOrchestratorImpl implements ImageOrchestrator {
|
||||
SecondaryStorageManager _secStorageMgr;
|
||||
@Inject
|
||||
VMTemplateZoneDao _templateZoneDao;
|
||||
|
||||
public void registerTemplate(long templateId) {
|
||||
List<VMTemplateZoneVO> tpZones = _templateZoneDao.listByTemplateId(templateId);
|
||||
|
||||
@ -74,5 +75,4 @@ public class ImageOrchestratorImpl implements ImageOrchestrator {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,15 +21,22 @@ package org.apache.cloudstack.storage.image;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
|
||||
|
||||
public interface ImageService {
|
||||
boolean registerTemplate(long templateId, long imageStoreId);
|
||||
TemplateEntity registerTemplate(long templateId, long imageStoreId);
|
||||
|
||||
boolean deleteTemplate(long templateId);
|
||||
|
||||
long registerIso(String isoUrl, long accountId);
|
||||
|
||||
boolean deleteIso(long isoId);
|
||||
TemplateInfo grantTemplateAccess(TemplateInfo template, EndPoint endpointId);
|
||||
|
||||
boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId);
|
||||
|
||||
boolean revokeTemplateAccess(long templateId, long endpointId);
|
||||
|
||||
String grantIsoAccess(long isoId, long endpointId);
|
||||
|
||||
boolean revokeIsoAccess(long isoId, long endpointId);
|
||||
|
||||
TemplateEntity getTemplateEntity(long templateId);
|
||||
}
|
||||
|
||||
@ -26,22 +26,18 @@ import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ImageServiceImpl implements ImageService {
|
||||
|
||||
@Inject
|
||||
ImageDataStoreProviderManager imageStoreProviderMgr;
|
||||
@Inject
|
||||
|
||||
@Override
|
||||
public boolean registerTemplate(long templateId, long imageStoreId) {
|
||||
public TemplateEntity registerTemplate(long templateId, long imageStoreId) {
|
||||
ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
|
||||
TemplateInfo template = ids.registerTemplate(templateId);
|
||||
if (ids.needDownloadToCacheStorage()) {
|
||||
ImageDownloader imageDl = ids.getImageDownloader();
|
||||
imageDl.downloadImage(template);
|
||||
}
|
||||
return true;
|
||||
TemplateObject to = ids.registerTemplate(templateId);
|
||||
return new TemplateEntityImpl(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,13 +78,14 @@ public class ImageServiceImpl implements ImageService {
|
||||
|
||||
@Override
|
||||
public TemplateEntity getTemplateEntity(long templateId) {
|
||||
TemplateObject to = imageStoreProviderMgr.getTemplate(templateId);
|
||||
ImageDataStore dataStore = imageStoreProviderMgr.getDataStoreFromTemplateId(templateId);
|
||||
TemplateObject to = dataStore.getTemplate(templateId);
|
||||
return new TemplateEntityImpl(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateInfo grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
|
||||
public boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import com.cloud.storage.Storage.TemplateType;
|
||||
|
||||
public class TemplateEntityImpl implements TemplateEntity {
|
||||
protected TemplateInfo templateInfo;
|
||||
|
||||
public TemplateEntityImpl(TemplateInfo templateInfo) {
|
||||
this.templateInfo = templateInfo;
|
||||
}
|
||||
@ -40,7 +41,6 @@ public class TemplateEntityImpl implements TemplateEntity {
|
||||
return templateInfo.getImageDataStore();
|
||||
}
|
||||
|
||||
|
||||
public long getImageDataStoreId() {
|
||||
return getImageDataStore().getImageDataStoreId();
|
||||
}
|
||||
@ -51,14 +51,18 @@ public class TemplateEntityImpl implements TemplateEntity {
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.templateInfo.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return this.templateInfo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExternalId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,6 +23,12 @@ import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
|
||||
public interface TemplateInfo {
|
||||
ImageDataStoreInfo getImageDataStore();
|
||||
|
||||
long getId();
|
||||
|
||||
VolumeDiskType getDiskType();
|
||||
|
||||
String getPath();
|
||||
|
||||
String getUuid();
|
||||
}
|
||||
|
||||
@ -25,23 +25,37 @@ import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
|
||||
public class TemplateObject implements TemplateInfo {
|
||||
private ImageDataVO imageVO;
|
||||
public TemplateObject(ImageDataVO template) {
|
||||
private ImageDataStoreInfo dataStore;
|
||||
|
||||
public TemplateObject(ImageDataVO template, ImageDataStoreInfo dataStore) {
|
||||
this.imageVO = template;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStoreInfo getImageDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return this.imageVO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeDiskType getDiskType() {
|
||||
return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
//TODO: add installation path if it's downloaded to cache storage already
|
||||
return this.imageVO.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.db;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
@Component
|
||||
public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao {
|
||||
|
||||
|
||||
@ -32,40 +32,50 @@ import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ImageDataDao extends GenericDao<ImageDataVO, Long> {
|
||||
public List<ImageDataVO> listByPublic();
|
||||
|
||||
public ImageDataVO findByName(String templateName);
|
||||
|
||||
public ImageDataVO findByTemplateName(String templateName);
|
||||
|
||||
// public void update(ImageDataVO template);
|
||||
|
||||
|
||||
public List<ImageDataVO> listAllSystemVMTemplates();
|
||||
|
||||
public List<ImageDataVO> listDefaultBuiltinTemplates();
|
||||
|
||||
public String getRoutingTemplateUniqueName();
|
||||
|
||||
public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
|
||||
|
||||
public List<ImageDataVO> listReadyTemplates();
|
||||
|
||||
public List<ImageDataVO> listByAccountId(long accountId);
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
|
||||
List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
|
||||
HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
|
||||
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
|
||||
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
|
||||
|
||||
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter,
|
||||
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
|
||||
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
|
||||
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
|
||||
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
|
||||
|
||||
public long addTemplateToZone(ImageDataVO tmplt, long zoneId);
|
||||
|
||||
public List<ImageDataVO> listAllInZone(long dataCenterId);
|
||||
|
||||
public List<ImageDataVO> listByHypervisorType(List<HypervisorType> hyperTypes);
|
||||
|
||||
public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
|
||||
|
||||
public List<ImageDataVO> userIsoSearch(boolean listRemoved);
|
||||
|
||||
ImageDataVO findSystemVMTemplate(long zoneId);
|
||||
|
||||
ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType);
|
||||
|
||||
ImageDataVO findRoutingTemplate(HypervisorType type);
|
||||
|
||||
List<Long> listPrivateTemplatesByHost(Long hostId);
|
||||
|
||||
public Long countTemplatesForAccount(long accountId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Filter;
|
||||
@ -75,24 +76,24 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implements ImageDataDao {
|
||||
private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class);
|
||||
|
||||
@Inject
|
||||
VMTemplateZoneDao _templateZoneDao;
|
||||
@Inject
|
||||
VMTemplateDetailsDao _templateDetailsDao;
|
||||
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
DomainDao _domainDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
VMTemplateZoneDao _templateZoneDao = null;
|
||||
|
||||
private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
|
||||
VMTemplateDetailsDao _templateDetailsDao = null;
|
||||
|
||||
|
||||
ConfigurationDao _configDao = null;
|
||||
|
||||
HostDao _hostDao = null;
|
||||
|
||||
DomainDao _domainDao = null;
|
||||
|
||||
DataCenterDao _dcDao = null;
|
||||
private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
|
||||
+ "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
|
||||
private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
|
||||
+ "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
|
||||
|
||||
private final String SELECT_TEMPLATE_SWIFT_REF = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
|
||||
+ "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
@ -111,9 +112,8 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
private SearchBuilder<ImageDataVO> UserIsoSearch;
|
||||
private GenericSearchBuilder<ImageDataVO, Long> CountTemplatesByAccount;
|
||||
|
||||
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
|
||||
|
||||
|
||||
//ResourceTagsDaoImpl _tagsDao = ComponentInject.inject(ResourceTagsDaoImpl.class);
|
||||
ResourceTagsDaoImpl _tagsDao = null;
|
||||
private String routerTmpltName;
|
||||
private String consoleProxyTmpltName;
|
||||
|
||||
@ -208,6 +208,7 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImageDataVO> listAllSystemVMTemplates() {
|
||||
SearchCriteria<ImageDataVO> sc = tmpltTypeSearch.create();
|
||||
@ -338,7 +339,6 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ);
|
||||
tmpltTypeHyperSearch2.and("hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ);
|
||||
|
||||
|
||||
tmpltTypeSearch = createSearchBuilder();
|
||||
tmpltTypeSearch.and("removed", tmpltTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
|
||||
@ -493,12 +493,10 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
return templateZonePairList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter,
|
||||
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
|
||||
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List<Account> permittedAccounts,
|
||||
Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
|
||||
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
for (Account permittedAccount : permittedAccounts) {
|
||||
@ -554,18 +552,18 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
sql += guestOSJoin + templateHostRefJoin + dataCenterJoin + lpjoin + tagsJoin;
|
||||
String whereClause = "";
|
||||
|
||||
//All joins have to be made before we start setting the condition settings
|
||||
if ((listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources
|
||||
|| (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.featured))) &&
|
||||
!(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter == TemplateFilter.all)) {
|
||||
// All joins have to be made before we start setting the condition
|
||||
// settings
|
||||
if ((listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources || (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.featured)))
|
||||
&& !(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter == TemplateFilter.all)) {
|
||||
whereClause += " INNER JOIN account a on (t.account_id = a.id)";
|
||||
if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
|
||||
if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
|
||||
&& (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
|
||||
whereClause += " INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" + domain.getPath() + "%'";
|
||||
if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
whereClause += " AND a.type != " + Account.ACCOUNT_TYPE_PROJECT;
|
||||
}
|
||||
} else
|
||||
if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
} else if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
whereClause += " WHERE a.type != " + Account.ACCOUNT_TYPE_PROJECT;
|
||||
}
|
||||
}
|
||||
@ -621,8 +619,8 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
}
|
||||
}
|
||||
|
||||
if (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.featured ||
|
||||
templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.executable) && !isAdmin(caller.getType()) ) {
|
||||
if (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.executable)
|
||||
&& !isAdmin(caller.getType())) {
|
||||
whereClause += attr + "t.account_id IN (" + permittedAccountsStr + ")";
|
||||
}
|
||||
|
||||
@ -634,9 +632,7 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
} else if (templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) {
|
||||
whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")";
|
||||
} else if (templateFilter == TemplateFilter.sharedexecutable) {
|
||||
whereClause += " AND " +
|
||||
" (t.account_id IN (" + permittedAccountsStr + ") OR" +
|
||||
" lp.account_id IN (" + permittedAccountsStr + "))";
|
||||
whereClause += " AND " + " (t.account_id IN (" + permittedAccountsStr + ") OR" + " lp.account_id IN (" + permittedAccountsStr + "))";
|
||||
} else if (templateFilter == TemplateFilter.executable && !permittedAccounts.isEmpty()) {
|
||||
whereClause += attr + "(t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
|
||||
} else if (templateFilter == TemplateFilter.community) {
|
||||
@ -667,8 +663,7 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
whereClause += " AND ";
|
||||
}
|
||||
|
||||
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId,
|
||||
onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
|
||||
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
|
||||
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
@ -677,15 +672,23 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), rs.getLong(2));
|
||||
templateZonePairList.add(templateZonePair);
|
||||
}
|
||||
//for now, defaulting pageSize to a large val if null; may need to revisit post 2.2RC2
|
||||
if(isIso && templateZonePairList.size() < (pageSize != null ? pageSize : 500)
|
||||
&& templateFilter != TemplateFilter.community
|
||||
&& !(templateFilter == TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType())) ){ //evaluates to true If root admin and filter=self
|
||||
// for now, defaulting pageSize to a large val if null; may need to
|
||||
// revisit post 2.2RC2
|
||||
if (isIso && templateZonePairList.size() < (pageSize != null ? pageSize : 500) && templateFilter != TemplateFilter.community
|
||||
&& !(templateFilter == TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType()))) { // evaluates
|
||||
// to
|
||||
// true
|
||||
// If
|
||||
// root
|
||||
// admin
|
||||
// and
|
||||
// filter=self
|
||||
|
||||
List<ImageDataVO> publicIsos = publicIsoSearch(bootable, false, tags);
|
||||
List<ImageDataVO> userIsos = userIsoSearch(false);
|
||||
|
||||
//Listing the ISOs according to the page size.Restricting the total no. of ISOs on a page
|
||||
// Listing the ISOs according to the page size.Restricting the
|
||||
// total no. of ISOs on a page
|
||||
// to be less than or equal to the pageSize parameter
|
||||
|
||||
int i = 0;
|
||||
@ -729,7 +732,8 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
return templateZonePairList;
|
||||
}
|
||||
|
||||
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) {
|
||||
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady,
|
||||
boolean showDomr) {
|
||||
String sql = "";
|
||||
if (keyword != null) {
|
||||
sql += " t.name LIKE \"%" + keyword + "%\" AND";
|
||||
@ -840,7 +844,8 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
|
||||
sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
|
||||
|
||||
//order by descending order of id and select the first (this is going to be the latest)
|
||||
// order by descending order of id and select the first (this is going
|
||||
// to be the latest)
|
||||
List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l));
|
||||
|
||||
if (tmplts.size() > 0) {
|
||||
@ -876,7 +881,8 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
|
||||
sc.setParameters("hypervisorType", hType);
|
||||
|
||||
//order by descending order of id and select the first (this is going to be the latest)
|
||||
// order by descending order of id and select the first (this is going
|
||||
// to be the latest)
|
||||
List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l));
|
||||
|
||||
if (tmplts.size() > 0) {
|
||||
@ -916,10 +922,7 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
|
||||
}
|
||||
|
||||
private 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));
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,5 +21,4 @@ package org.apache.cloudstack.storage.image.db;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> {
|
||||
|
||||
}
|
||||
|
||||
@ -135,7 +135,6 @@ public class ImageDataVO implements Identity {
|
||||
@Transient
|
||||
Map details;
|
||||
|
||||
|
||||
public String getUniqueName() {
|
||||
return uniqueName;
|
||||
}
|
||||
@ -353,6 +352,7 @@ public class ImageDataVO implements Identity {
|
||||
|
||||
@Transient
|
||||
String toString;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (toString == null) {
|
||||
@ -381,7 +381,7 @@ public class ImageDataVO implements Identity {
|
||||
enableSshKey = enable;
|
||||
}
|
||||
|
||||
public long getImageDataStoreId() {
|
||||
public Long getImageDataStoreId() {
|
||||
return this.imageDataStoreId;
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,10 @@ import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
|
||||
public interface ImageDataStoreDriver {
|
||||
boolean registerTemplate(TemplateInfo template);
|
||||
|
||||
String grantAccess(long templateId, long endPointId);
|
||||
|
||||
boolean revokeAccess(long templateId, long endPointId);
|
||||
|
||||
boolean deleteTemplate(TemplateInfo template);
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
|
||||
|
||||
public ImageDataStoreDriverImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerTemplate(TemplateInfo template) {
|
||||
// TODO: check the availability of template
|
||||
@ -48,6 +49,4 @@ public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class BAREMETAL extends BaseType implements ImageFormat {
|
||||
private final String type = "BAREMETAL";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class ISO extends BaseType implements ImageFormat {
|
||||
private final String type = "ISO";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -28,6 +28,7 @@ import org.springframework.stereotype.Component;
|
||||
public class ImageFormatHelper {
|
||||
private static List<ImageFormat> formats;
|
||||
private static final ImageFormat defaultFormat = new Unknown();
|
||||
|
||||
@Inject
|
||||
public void setFormats(List<ImageFormat> formats) {
|
||||
ImageFormatHelper.formats = formats;
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class OVA extends BaseType implements ImageFormat {
|
||||
private final String type = "OVA";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component("imageformat_qcow2")
|
||||
public class QCOW2 extends BaseType implements ImageFormat {
|
||||
private final String type = "QCOW2";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -19,9 +19,12 @@
|
||||
package org.apache.cloudstack.storage.image.format;
|
||||
|
||||
import org.apache.cloudstack.storage.BaseType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VHD extends BaseType implements ImageFormat {
|
||||
private final String type = "VHD";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
|
||||
@ -31,6 +31,7 @@ public class ImageDataStoreManagerImpl implements ImageDataStoreManager {
|
||||
ImageDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
|
||||
@Override
|
||||
public ImageDataStore getImageDataStore(long dataStoreId) {
|
||||
ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId);
|
||||
|
||||
@ -29,7 +29,9 @@ import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DefaultImageMotionStrategy implements ImageMotionStrategy {
|
||||
|
||||
@Override
|
||||
|
||||
@ -22,5 +22,6 @@ import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
|
||||
public interface ImageMotionService {
|
||||
boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore);
|
||||
|
||||
boolean copyIso(String isoUri, String destIsoUri);
|
||||
}
|
||||
|
||||
@ -31,9 +31,11 @@ import org.apache.cloudstack.storage.image.ImageService;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class ImageMotionServiceImpl implements ImageMotionService {
|
||||
@Inject
|
||||
List<ImageMotionStrategy> motionStrategies;
|
||||
@ -41,6 +43,7 @@ public class ImageMotionServiceImpl implements ImageMotionService {
|
||||
VolumeService volumeService;
|
||||
@Inject
|
||||
ImageService imageService;
|
||||
|
||||
@Override
|
||||
public boolean copyIso(String isoUri, String destIsoUri) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -23,6 +23,8 @@ import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
|
||||
public interface ImageMotionStrategy {
|
||||
public boolean canHandle(TemplateOnPrimaryDataStoreInfo templateStore);
|
||||
|
||||
public EndPoint getEndPoint(TemplateOnPrimaryDataStoreInfo templateStore);
|
||||
|
||||
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep);
|
||||
}
|
||||
|
||||
@ -50,4 +50,10 @@ public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(long providerId) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,5 +22,6 @@ import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public interface ImageDataStoreProvider {
|
||||
ImageDataStore getImageDataStore(long imageStoreId);
|
||||
boolean register(long providerId);
|
||||
public String getName();
|
||||
}
|
||||
|
||||
@ -21,9 +21,12 @@ package org.apache.cloudstack.storage.image.provider;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public interface ImageDataStoreProviderManager {
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface ImageDataStoreProviderManager extends Manager {
|
||||
public ImageDataStoreProvider getProvider(long providerId);
|
||||
public ImageDataStore getDataStore(long dataStoreId);
|
||||
|
||||
public ImageDataStore getDataStore(Long dataStoreId);
|
||||
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId);
|
||||
public TemplateObject getTemplate(long templateId);
|
||||
}
|
||||
|
||||
@ -19,8 +19,10 @@
|
||||
package org.apache.cloudstack.storage.image.provider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
@ -42,6 +44,7 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
|
||||
ImageDataDao imageDataDao;
|
||||
@Inject
|
||||
List<ImageDataStoreProvider> providers;
|
||||
|
||||
@Override
|
||||
public ImageDataStoreProvider getProvider(long providerId) {
|
||||
|
||||
@ -58,8 +61,16 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStore getDataStore(long dataStoreId) {
|
||||
public ImageDataStore getDataStore(Long dataStoreId) {
|
||||
if (dataStoreId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ImageDataStoreVO idsv = dataStoreDao.findById(dataStoreId);
|
||||
if (idsv == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
long providerId = idsv.getProvider();
|
||||
ImageDataStoreProviderVO idspv = providerDao.findById(providerId);
|
||||
ImageDataStoreProvider provider = getProvider(idspv.getName());
|
||||
@ -69,11 +80,49 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
|
||||
@Override
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId) {
|
||||
ImageDataVO iddv = imageDataDao.findById(templateId);
|
||||
return getDataStore(iddv.getId());
|
||||
return getDataStore(iddv.getImageDataStoreId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateObject getTemplate(long templateId) {
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
List<ImageDataStoreProviderVO> existingProviders = providerDao.listAll();
|
||||
//TODO: hold global lock
|
||||
boolean foundExistingProvider = false;
|
||||
for (ImageDataStoreProvider provider : providers) {
|
||||
foundExistingProvider = false;
|
||||
for (ImageDataStoreProviderVO existingProvider : existingProviders) {
|
||||
if (provider.getName().equalsIgnoreCase(existingProvider.getName())) {
|
||||
foundExistingProvider = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundExistingProvider) {
|
||||
//add a new provider into db
|
||||
ImageDataStoreProviderVO nProvider = new ImageDataStoreProviderVO();
|
||||
nProvider.setName(provider.getName());
|
||||
nProvider = providerDao.persist(nProvider);
|
||||
provider.register(nProvider.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -19,14 +19,21 @@
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
|
||||
public interface ImageDataStore extends ImageDataStoreInfo {
|
||||
TemplateInfo registerTemplate(long templateId);
|
||||
TemplateObject registerTemplate(long templateId);
|
||||
|
||||
String grantAccess(long templateId, long endPointId);
|
||||
|
||||
boolean revokeAccess(long templateId, long endPointId);
|
||||
|
||||
boolean deleteTemplate(long templateId);
|
||||
|
||||
boolean needDownloadToCacheStorage();
|
||||
|
||||
ImageDownloader getImageDownloader();
|
||||
|
||||
TemplateObject getTemplate(long templateId);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.store;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
@ -36,25 +37,20 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
ImageDataStoreVO imageDataStoreVO;
|
||||
boolean needDownloadToCacheStorage = false;
|
||||
|
||||
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
|
||||
this.driver = driver;
|
||||
this.needDownloadToCacheStorage = needDownloadToCacheStorage;
|
||||
this.downloader = downloader;
|
||||
this.imageDataStoreVO = dataStoreVO;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public TemplateInfo registerTemplate(long templateId) {
|
||||
ImageDataVO idv = imageDao.findById(templateId);
|
||||
TemplateInfo template = new TemplateInfo(this, idv);
|
||||
if (driver.registerTemplate(template)) {
|
||||
template.setImageDataStoreId(imageDataStoreVO.getId());
|
||||
return template;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
* @Override public TemplateInfo registerTemplate(long templateId) {
|
||||
* ImageDataVO idv = imageDao.findById(templateId); TemplateInfo template =
|
||||
* new TemplateInfo(this, idv); if (driver.registerTemplate(template)) {
|
||||
* template.setImageDataStoreId(imageDataStoreVO.getId()); return template;
|
||||
* } else { return null; } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String grantAccess(long templateId, long endPointId) {
|
||||
@ -92,9 +88,18 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateInfo registerTemplate(long templateId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public TemplateObject registerTemplate(long templateId) {
|
||||
ImageDataVO image = imageDao.findById(templateId);
|
||||
image.setImageDataStoreId(this.getImageDataStoreId());
|
||||
imageDao.update(templateId, image);
|
||||
return getTemplate(templateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateObject getTemplate(long templateId) {
|
||||
ImageDataVO image = imageDao.findById(templateId);
|
||||
TemplateObject to = new TemplateObject(image, this);
|
||||
return to;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,9 +23,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
|
||||
|
||||
public class DefaultNfsSecondaryLifeCycle implements DataStoreLifeCycle {
|
||||
protected DataStore _ds;
|
||||
|
||||
public DefaultNfsSecondaryLifeCycle(DataStore ds) {
|
||||
_ds = ds;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
@ -32,11 +32,11 @@ public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle {
|
||||
StoragePoolDao _storagePoolDao;
|
||||
@Inject
|
||||
StoragePoolHostDao _poolHostDao;
|
||||
|
||||
public DefaultPrimaryDataStoreLifeCycle(DataStore ds) {
|
||||
this._ds = ds;
|
||||
}
|
||||
|
||||
|
||||
protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO pool) {
|
||||
DataStoreDriver dsDriver = _ds.getDataStoreDriver();
|
||||
CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool);
|
||||
|
||||
@ -28,11 +28,15 @@ import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
public interface BackupStorageManager {
|
||||
boolean contains(Volume vol);
|
||||
|
||||
boolean contains(Snapshot snapshot);
|
||||
|
||||
boolean contains(VirtualMachineTemplate template);
|
||||
|
||||
DataStore getBackupDataStore(Volume vol);
|
||||
|
||||
DataStore getBackupDataStore(Snapshot snapshot);
|
||||
|
||||
DataStore getBackupDataStore(VirtualMachineTemplate template);
|
||||
|
||||
boolean updateOperationState(Volume vol, DataObjectBackupStorageOperationState.Event event) throws NoTransitionException;
|
||||
|
||||
@ -27,16 +27,17 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
public interface PrimaryDataStoreManager {
|
||||
PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId,
|
||||
String URI,
|
||||
String storageType,
|
||||
String poolName,
|
||||
String storageProviderName,
|
||||
Map<String, String> params);
|
||||
PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params);
|
||||
|
||||
void deleteStoragePool(long poolId);
|
||||
|
||||
void enableStoragePool(long poolId);
|
||||
|
||||
void disableStoragePool(long poolId);
|
||||
|
||||
Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor);
|
||||
|
||||
Map<String, List<String>> getSupportedSecondaryStorages(long zoneId);
|
||||
|
||||
PrimaryDataStore getDataStore(String id);
|
||||
}
|
||||
|
||||
@ -28,7 +28,10 @@ import com.cloud.template.VirtualMachineTemplate;
|
||||
|
||||
public interface SecondaryStorageManager {
|
||||
DataStore getStore(Volume volume);
|
||||
|
||||
DataStore getImageStore(DataStore destStore);
|
||||
|
||||
List<DataStore> getImageStores(long zoneId);
|
||||
|
||||
DataStore getStore(Snapshot snapshot);
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import com.cloud.storage.StoragePool;
|
||||
public class DefaultNfsSecondaryStorageProvider implements StorageProvider {
|
||||
private String _name = DefaultPrimaryStorageProvider.class.toString();
|
||||
protected Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
|
||||
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
|
||||
DataStoreConfigurator nfsdc = null;
|
||||
|
||||
@ -68,8 +68,7 @@ public class DefaultPrimaryStorageProvider implements StorageProvider {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public DataStore createDataStore(HypervisorType hypervisor,
|
||||
DataStoreConfigurator dsc) {
|
||||
public DataStore createDataStore(HypervisorType hypervisor, DataStoreConfigurator dsc) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -20,5 +20,6 @@ package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
public interface SnapshotService {
|
||||
long takeSnapshot(long volumeId);
|
||||
|
||||
boolean deleteSnapshot(long snapshotId);
|
||||
}
|
||||
|
||||
@ -16,12 +16,10 @@ import org.apache.cloudstack.storage.volume.VolumeManager;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
|
||||
public class DefaultVolumeStrategy implements VolumeStrategy {
|
||||
private static final Logger s_logger = Logger.getLogger(DefaultVolumeStrategy.class);
|
||||
protected DataStore _ds;
|
||||
@ -36,26 +34,32 @@ public class DefaultVolumeStrategy implements VolumeStrategy {
|
||||
public DefaultVolumeStrategy(DataStore ds) {
|
||||
_ds = ds;
|
||||
}
|
||||
|
||||
public Volume createVolume(Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Volume createDataVolume(Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Volume copyVolumeFromBackup(VolumeProfile srcVol, Volume destVol) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Volume createVolumeFromSnapshot(SnapshotProfile snapshot, Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Volume createVolumeFromTemplate(TemplateProfile template, Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Volume migrateVolume(Volume srcVol, Volume destVol, DataStore destStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
@ -79,12 +83,10 @@ public class DefaultVolumeStrategy implements VolumeStrategy {
|
||||
|
||||
return _volumeMgr.updateVolume(vlvo);
|
||||
}
|
||||
|
||||
public boolean deleteVolume(Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
|
||||
public class XenBackupStrategy implements BackupStrategy {
|
||||
protected DataStore _ds;
|
||||
|
||||
public XenBackupStrategy(DataStore ds) {
|
||||
_ds = ds;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
|
||||
|
||||
public class XenSnapshotStrategy implements SnapshotStrategy {
|
||||
protected DataStore _ds;
|
||||
|
||||
public XenSnapshotStrategy(DataStore ds) {
|
||||
_ds = ds;
|
||||
}
|
||||
|
||||
@ -23,7 +23,10 @@ import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
|
||||
public interface TemplateOnPrimaryDataStoreInfo {
|
||||
public String getPath();
|
||||
|
||||
public void setPath(String path);
|
||||
|
||||
public PrimaryDataStoreInfo getPrimaryDataStore();
|
||||
|
||||
public TemplateInfo getTemplate();
|
||||
}
|
||||
|
||||
@ -23,5 +23,6 @@ import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
|
||||
public interface TemplatePrimaryDataStoreManager {
|
||||
public TemplateOnPrimaryDataStoreInfo createTemplateOnPrimaryDataStore(TemplateInfo template, PrimaryDataStoreInfo dataStore);
|
||||
|
||||
public TemplateOnPrimaryDataStoreInfo findTemplateOnPrimaryDataStore(TemplateInfo template, PrimaryDataStoreInfo dataStore);
|
||||
}
|
||||
|
||||
@ -24,15 +24,18 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.volume.db.TemplatePrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.volume.db.TemplatePrimaryDataStoreVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
@Component
|
||||
public class TemplatePrimaryDataStoreManagerImpl implements TemplatePrimaryDataStoreManager {
|
||||
@Inject
|
||||
TemplatePrimaryDataStoreDao templateStoreDao;
|
||||
|
||||
@Override
|
||||
public TemplateOnPrimaryDataStoreObject createTemplateOnPrimaryDataStore(TemplateInfo template, PrimaryDataStoreInfo dataStore) {
|
||||
|
||||
@ -41,6 +44,7 @@ public class TemplatePrimaryDataStoreManagerImpl implements TemplatePrimaryDataS
|
||||
TemplateOnPrimaryDataStoreObject templateStoreObject = new TemplateOnPrimaryDataStoreObject(dataStore, template, templateStoreVO);
|
||||
return templateStoreObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOnPrimaryDataStoreObject findTemplateOnPrimaryDataStore(TemplateInfo template, PrimaryDataStoreInfo dataStore) {
|
||||
SearchCriteriaService<TemplatePrimaryDataStoreVO, TemplatePrimaryDataStoreVO> sc = SearchCriteria2.create(TemplatePrimaryDataStoreVO.class);
|
||||
|
||||
@ -55,6 +55,12 @@ public class VolumeEntityImpl implements VolumeEntity {
|
||||
return volumeInfo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExternalId() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentState() {
|
||||
return volumeInfo.getCurrentState().toString();
|
||||
|
||||
@ -19,16 +19,5 @@
|
||||
package org.apache.cloudstack.storage.volume;
|
||||
|
||||
public enum VolumeEvent {
|
||||
CreateRequested,
|
||||
CopyRequested,
|
||||
CopySucceeded,
|
||||
CopyFailed,
|
||||
OperationFailed,
|
||||
OperationSucceeded,
|
||||
OperationRetry,
|
||||
UploadRequested,
|
||||
MigrationRequested,
|
||||
SnapshotRequested,
|
||||
DestroyRequested,
|
||||
ExpungingRequested;
|
||||
CreateRequested, CopyRequested, CopySucceeded, CopyFailed, OperationFailed, OperationSucceeded, OperationRetry, UploadRequested, MigrationRequested, SnapshotRequested, DestroyRequested, ExpungingRequested;
|
||||
}
|
||||
|
||||
@ -26,8 +26,12 @@ import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
public interface VolumeManager {
|
||||
VolumeVO allocateDuplicateVolume(VolumeVO oldVol);
|
||||
|
||||
VolumeVO processEvent(Volume vol, Volume.Event event) throws NoTransitionException;
|
||||
|
||||
VolumeProfile getProfile(long volumeId);
|
||||
|
||||
VolumeVO getVolume(long volumeId);
|
||||
|
||||
VolumeVO updateVolume(VolumeVO volume);
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ public class VolumeManagerImpl implements VolumeManager {
|
||||
@Inject
|
||||
protected VolumeDao _volumeDao;
|
||||
|
||||
|
||||
public VolumeVO allocateDuplicateVolume(VolumeVO oldVol) {
|
||||
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
|
||||
newVol.setTemplateId(oldVol.getTemplateId());
|
||||
@ -44,25 +43,21 @@ public class VolumeManagerImpl implements VolumeManager {
|
||||
// return _volumeDao.persist(newVol);
|
||||
}
|
||||
|
||||
|
||||
public VolumeVO processEvent(Volume vol, Volume.Event event) throws NoTransitionException {
|
||||
// _volStateMachine.transitTo(vol, event, null, _volumeDao);
|
||||
return _volumeDao.findById(vol.getId());
|
||||
}
|
||||
|
||||
|
||||
public VolumeProfile getProfile(long volumeId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public VolumeVO getVolume(long volumeId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public VolumeVO updateVolume(VolumeVO volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package org.apache.cloudstack.storage.volume;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -26,7 +26,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
|
||||
|
||||
public interface VolumeService {
|
||||
/**
|
||||
*
|
||||
@ -44,6 +43,7 @@ public interface VolumeService {
|
||||
|
||||
/**
|
||||
* Delete volume
|
||||
*
|
||||
* @param volumeId
|
||||
* @return
|
||||
* @throws ConcurrentOperationException
|
||||
@ -73,5 +73,6 @@ public interface VolumeService {
|
||||
boolean rokeAccess(long volumeId, long endpointId);
|
||||
|
||||
VolumeEntity getVolumeEntity(long volumeId);
|
||||
|
||||
VolumeInfo createVolumeFromTemplate(VolumeInfo volume, long dataStoreId, VolumeDiskType diskType, TemplateInfo template);
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
|
||||
@Inject
|
||||
ImageMotionService imageMotion;
|
||||
|
||||
@Override
|
||||
public VolumeInfo createVolume(VolumeInfo volume, long dataStoreId, VolumeDiskType diskType) {
|
||||
PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(dataStoreId);
|
||||
@ -124,7 +125,6 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String grantAccess(VolumeInfo volume, EndPoint endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -45,29 +45,40 @@ public class TemplatePrimaryDataStoreVO {
|
||||
@Column(name = "pool_id")
|
||||
private long poolId;
|
||||
|
||||
@Column(name="template_id") long templateId;
|
||||
@Column(name = "template_id")
|
||||
long templateId;
|
||||
|
||||
@Column(name=GenericDaoBase.CREATED_COLUMN) Date created = null;
|
||||
@Column(name = GenericDaoBase.CREATED_COLUMN)
|
||||
Date created = null;
|
||||
|
||||
@Column(name = "last_updated")
|
||||
@Temporal(value=TemporalType.TIMESTAMP) Date lastUpdated = null;
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
Date lastUpdated = null;
|
||||
|
||||
@Column (name="download_pct") int downloadPercent;
|
||||
@Column(name = "download_pct")
|
||||
int downloadPercent;
|
||||
|
||||
@Column(name = "download_state")
|
||||
@Enumerated(EnumType.STRING) Status downloadState;
|
||||
@Enumerated(EnumType.STRING)
|
||||
Status downloadState;
|
||||
|
||||
@Column (name="local_path") String localDownloadPath;
|
||||
@Column(name = "local_path")
|
||||
String localDownloadPath;
|
||||
|
||||
@Column (name="error_str") String errorString;
|
||||
@Column(name = "error_str")
|
||||
String errorString;
|
||||
|
||||
@Column (name="job_id") String jobId;
|
||||
@Column(name = "job_id")
|
||||
String jobId;
|
||||
|
||||
@Column (name="install_path") String installPath;
|
||||
@Column(name = "install_path")
|
||||
String installPath;
|
||||
|
||||
@Column (name="template_size") long templateSize;
|
||||
@Column(name = "template_size")
|
||||
long templateSize;
|
||||
|
||||
@Column (name="marked_for_gc") boolean markedForGC;
|
||||
@Column(name = "marked_for_gc")
|
||||
boolean markedForGC;
|
||||
|
||||
public String getInstallPath() {
|
||||
return installPath;
|
||||
@ -137,9 +148,7 @@ public class TemplatePrimaryDataStoreVO {
|
||||
this.markedForGC = false;
|
||||
}
|
||||
|
||||
public TemplatePrimaryDataStoreVO(long poolId, long templateId, Date lastUpdated,
|
||||
int downloadPercent, Status downloadState,
|
||||
String localDownloadPath, String errorString, String jobId,
|
||||
public TemplatePrimaryDataStoreVO(long poolId, long templateId, Date lastUpdated, int downloadPercent, Status downloadState, String localDownloadPath, String errorString, String jobId,
|
||||
String installPath, long templateSize) {
|
||||
super();
|
||||
this.poolId = poolId;
|
||||
|
||||
@ -21,8 +21,6 @@ import java.util.List;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
|
||||
import org.apache.cloudstack.storage.volume.VolumeEvent;
|
||||
|
||||
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@ -61,14 +61,13 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
protected final SearchBuilder<VolumeVO> InstanceStatesSearch;
|
||||
protected final SearchBuilder<VolumeVO> AllFieldsSearch;
|
||||
protected GenericSearchBuilder<VolumeVO, Long> CountByAccount;
|
||||
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
|
||||
|
||||
//ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
|
||||
ResourceTagsDaoImpl _tagsDao = null;
|
||||
protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?";
|
||||
protected static final String SELECT_HYPERTYPE_FROM_VOLUME = "SELECT c.hypervisor_type from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and v.id = ?";
|
||||
|
||||
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? " +
|
||||
" AND pool.pod_id = ? AND pool.cluster_id = ? " +
|
||||
" GROUP BY pool.id ORDER BY 2 ASC ";
|
||||
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
|
||||
+ " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC ";
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findDetachedByAccount(long accountId) {
|
||||
@ -301,7 +300,8 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
CountByAccount.done();
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
@Override
|
||||
@DB(txn = false)
|
||||
public Pair<Long, Long> getCountAndTotalByPool(long poolId) {
|
||||
SearchCriteria<SumCount> sc = TotalSizeByPoolSearch.create();
|
||||
sc.setParameters("poolId", poolId);
|
||||
@ -321,6 +321,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
public static class SumCount {
|
||||
public long sum;
|
||||
public long count;
|
||||
|
||||
public SumCount() {
|
||||
}
|
||||
}
|
||||
@ -334,9 +335,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(Volume.State currentState,
|
||||
VolumeEvent event, Volume.State nextState, VolumeVO vo,
|
||||
Object data) {
|
||||
public boolean updateState(Volume.State currentState, VolumeEvent event, Volume.State nextState, VolumeVO vo, Object data) {
|
||||
|
||||
Long oldUpdated = vo.getUpdatedCount();
|
||||
Date oldUpdatedTime = vo.getUpdated();
|
||||
@ -357,9 +356,12 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
VolumeVO dbVol = findByIdIncludingRemoved(vo.getId());
|
||||
if (dbVol != null) {
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
|
||||
str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getUpdated());
|
||||
str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
|
||||
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
|
||||
.append(dbVol.getUpdated());
|
||||
str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount())
|
||||
.append("; updatedTime=").append(vo.getUpdated());
|
||||
str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated)
|
||||
.append("; updatedTime=").append(oldUpdatedTime);
|
||||
} else {
|
||||
s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore");
|
||||
}
|
||||
@ -392,7 +394,8 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
@Override
|
||||
@DB(txn = false)
|
||||
public Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId) {
|
||||
SearchCriteria<SumCount> sc = TotalSizeByPoolSearch.create();
|
||||
sc.setParameters("poolId", poolId);
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
//under the License.
|
||||
|
||||
package org.apache.cloudstack.storage.volume.db;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -33,8 +34,6 @@ import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.Unknown;
|
||||
|
||||
|
||||
|
||||
import com.cloud.api.Identity;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
@ -124,7 +123,10 @@ public class VolumeVO implements Identity, StateObject<Volume.State>{
|
||||
Date updated;
|
||||
|
||||
@Column(name = "update_count", updatable = true, nullable = false)
|
||||
protected long updatedCount; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
|
||||
protected long updatedCount; // This field should be updated everytime the
|
||||
// state is updated. There's no set method in
|
||||
// the vo object because it is done with in the
|
||||
// dao code.
|
||||
|
||||
@Column(name = "recreatable")
|
||||
boolean recreatable;
|
||||
@ -190,12 +192,10 @@ public class VolumeVO implements Identity, StateObject<Volume.State>{
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public Long getPodId() {
|
||||
return podId;
|
||||
}
|
||||
|
||||
|
||||
public long getDataCenterId() {
|
||||
return dataCenterId;
|
||||
}
|
||||
@ -423,4 +423,3 @@ public class VolumeVO implements Identity, StateObject<Volume.State>{
|
||||
diskType = type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,11 +21,13 @@ package org.apache.cloudstack.storage.test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD;
|
||||
@ -35,23 +37,18 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
|
||||
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
|
||||
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.format.ISO;
|
||||
import org.apache.cloudstack.storage.image.format.ImageFormat;
|
||||
import org.apache.cloudstack.storage.image.format.ImageFormatHelper;
|
||||
import org.apache.cloudstack.storage.image.format.OVA;
|
||||
import org.apache.cloudstack.storage.image.format.Unknown;
|
||||
import org.apache.cloudstack.storage.volume.VolumeMotionService;
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.mockito.Mockito.*;
|
||||
@ -61,37 +58,25 @@ import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.db.DB;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="storageContext.xml")
|
||||
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
|
||||
public class volumeServiceTest {
|
||||
@Autowired
|
||||
protected VolumeService volService;
|
||||
@Inject
|
||||
protected VolumeDao volumeDao;
|
||||
@Autowired
|
||||
protected VolumeMotionService vmotion;
|
||||
ImageDataStoreProviderManager imageProviderMgr;
|
||||
@Before
|
||||
public void setUp() {
|
||||
Mockito.when(vmotion.copyVolume(null, null)).thenReturn(false);
|
||||
|
||||
}
|
||||
|
||||
@DB
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(volService.deleteVolume(1) != false);
|
||||
assertNotNull(volumeDao);
|
||||
//VolumeVO vol = new VolumeVO(Volume.Type.DATADISK, "test", 1, 2, 2, 1, 1);
|
||||
//volumeDao.persist(vol);
|
||||
/*
|
||||
VolumeVO volume = new VolumeVO();
|
||||
String name = "test";
|
||||
long size = 100;
|
||||
volume.setName(name);
|
||||
volume.setSize(size);
|
||||
volumeDao.persist(volume);
|
||||
VolumeVO newVol = volumeDao.getVolumeByName(name);
|
||||
assertTrue(newVol.getSize() == volume.getSize());
|
||||
*/
|
||||
try {
|
||||
|
||||
fail("Not yet implemented");
|
||||
imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
|
||||
|
||||
} catch (ConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<context:component-scan base-package="org.apache.cloudstack.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.storage.dao" />
|
||||
|
||||
|
||||
<context:component-scan base-package=" com.cloud.upgrade.dao" />
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
@ -50,7 +50,6 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
@Local(value=VolumeDao.class)
|
||||
public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements VolumeDao {
|
||||
private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user