mirror of https://github.com/apache/cloudstack.git
add DeleteImageStoreCmd Api.
This commit is contained in:
parent
7f64b61cbd
commit
74880fa26f
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -24,5 +24,8 @@ import com.cloud.utils.db.GenericDao;
|
|||
public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long> {
|
||||
|
||||
void update(long storeId, Map<String, String> details);
|
||||
|
||||
Map<String, String> getDetails(long storeId);
|
||||
|
||||
void deleteDetails(long storeId);
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -14,14 +14,22 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
|
||||
public interface SnapshotDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, VolumeDataStoreVO> {
|
||||
public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, SnapshotDataStoreVO> {
|
||||
|
||||
public List<SnapshotDataStoreVO> listByStoreId(long id);
|
||||
|
||||
public List<SnapshotDataStoreVO> listLiveByStoreId(long id);
|
||||
|
||||
public void deletePrimaryRecordsForStore(long id);
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -14,9 +14,10 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
|
@ -24,4 +25,9 @@ import com.cloud.utils.fsm.StateDao;
|
|||
|
||||
public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, TemplateDataStoreVO> {
|
||||
|
||||
public List<TemplateDataStoreVO> listByStoreId(long id);
|
||||
|
||||
public List<TemplateDataStoreVO> listLiveByStoreId(long id);
|
||||
|
||||
public void deletePrimaryRecordsForStore(long id);
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -14,9 +14,11 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
|
@ -24,4 +26,9 @@ import com.cloud.utils.fsm.StateDao;
|
|||
|
||||
public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, VolumeDataStoreVO> {
|
||||
|
||||
public List<VolumeDataStoreVO> listByStoreId(long id);
|
||||
|
||||
public List<VolumeDataStoreVO> listLiveByStoreId(long id);
|
||||
|
||||
public void deletePrimaryRecordsForStore(long id);
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -29,11 +29,11 @@ import javax.inject.Inject;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
package org.apache.cloudstack.storage.db;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.DataStoreProviderVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
|
@ -23,10 +23,10 @@ import java.util.Map;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDetailVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDetailsDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.ImageStore;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,11 @@ import java.util.Map;
|
|||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -70,4 +73,18 @@ public class ImageStoreDetailsDaoImpl extends GenericDaoBase<ImageStoreDetailVO,
|
|||
|
||||
return detailsMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDetails(long storeId) {
|
||||
SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
|
||||
sc.setParameters("store", storeId);
|
||||
|
||||
List<ImageStoreDetailVO> results = search(sc, null);
|
||||
for (ImageStoreDetailVO result : results) {
|
||||
remove(result.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,32 +14,48 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.StoragePoolHostVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
|
||||
@Component
|
||||
public class SnapshotDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Long> implements VolumeDataStoreDao {
|
||||
public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO, Long> implements SnapshotDataStoreDao {
|
||||
private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class);
|
||||
private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> updateStateSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> storeSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> liveStoreSearch;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
storeSearch = createSearchBuilder();
|
||||
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
|
||||
storeSearch.done();
|
||||
|
||||
liveStoreSearch = createSearchBuilder();
|
||||
liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
|
||||
liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
liveStoreSearch.done();
|
||||
|
||||
updateStateSearch = this.createSearchBuilder();
|
||||
updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
|
||||
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
|
||||
|
|
@ -47,14 +63,15 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
|
|||
updateStateSearch.done();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State currentState, Event event,
|
||||
State nextState, VolumeDataStoreVO dataObj, Object data) {
|
||||
State nextState, SnapshotDataStoreVO dataObj, Object data) {
|
||||
Long oldUpdated = dataObj.getUpdatedCount();
|
||||
Date oldUpdatedTime = dataObj.getUpdated();
|
||||
|
||||
|
||||
SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = updateStateSearch.create();
|
||||
sc.setParameters("id", dataObj.getId());
|
||||
sc.setParameters("state", currentState);
|
||||
sc.setParameters("updatedCount", dataObj.getUpdatedCount());
|
||||
|
|
@ -67,7 +84,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
|
|||
|
||||
int rows = update(dataObj, sc);
|
||||
if (rows == 0 && s_logger.isDebugEnabled()) {
|
||||
VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
|
||||
SnapshotDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
|
||||
if (dbVol != null) {
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
|
||||
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
|
||||
|
|
@ -83,4 +100,31 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
|
|||
return rows > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotDataStoreVO> listByStoreId(long id) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotDataStoreVO> listLiveByStoreId(long id) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
sc.setParameters("destroyed", false);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePrimaryRecordsForStore(long id) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
remove(sc);
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,8 +14,9 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
|
@ -23,12 +24,16 @@ import javax.naming.ConfigurationException;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
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;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
|
||||
|
|
@ -36,17 +41,30 @@ import com.cloud.utils.db.UpdateBuilder;
|
|||
public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO, Long> implements TemplateDataStoreDao {
|
||||
private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class);
|
||||
private SearchBuilder<TemplateDataStoreVO> updateStateSearch;
|
||||
private SearchBuilder<TemplateDataStoreVO> storeSearch;
|
||||
private SearchBuilder<TemplateDataStoreVO> liveStoreSearch;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
updateStateSearch = this.createSearchBuilder();
|
||||
storeSearch = createSearchBuilder();
|
||||
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
|
||||
storeSearch.done();
|
||||
|
||||
liveStoreSearch = createSearchBuilder();
|
||||
liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
|
||||
liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
liveStoreSearch.done();
|
||||
|
||||
updateStateSearch = this.createSearchBuilder();
|
||||
updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
|
||||
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
|
||||
updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
|
||||
updateStateSearch.done();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State currentState, Event event,
|
||||
State nextState, TemplateDataStoreVO dataObj, Object data) {
|
||||
|
|
@ -83,4 +101,27 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
|||
return rows > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateDataStoreVO> listByStoreId(long id) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
@Override
|
||||
public List<TemplateDataStoreVO> listLiveByStoreId(long id) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
sc.setParameters("destroyed", false);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePrimaryRecordsForStore(long id) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
remove(sc);
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
|
@ -14,8 +14,9 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.db;
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
|
@ -23,12 +24,17 @@ import javax.naming.ConfigurationException;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
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;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
|
||||
|
|
@ -36,6 +42,9 @@ import com.cloud.utils.db.UpdateBuilder;
|
|||
public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Long> implements VolumeDataStoreDao {
|
||||
private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class);
|
||||
private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
|
||||
private SearchBuilder<VolumeDataStoreVO> storeSearch;
|
||||
private SearchBuilder<VolumeDataStoreVO> liveStoreSearch;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
|
@ -83,4 +92,27 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
|||
return rows > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeDataStoreVO> listByStoreId(long id) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
@Override
|
||||
public List<VolumeDataStoreVO> listLiveByStoreId(long id) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
sc.setParameters("destroyed", false);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePrimaryRecordsForStore(long id) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
remove(sc);
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
|
@ -14,11 +14,14 @@
|
|||
// 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;
|
||||
package org.apache.cloudstack.storage.volume.db;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailsDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
|
@ -29,10 +29,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
|
||||
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,17 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -78,6 +87,7 @@ import com.cloud.agent.api.ManageSnapshotCommand;
|
|||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DeleteVolumeCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
|
|
@ -125,6 +135,7 @@ import com.cloud.org.Grouping;
|
|||
import com.cloud.org.Grouping.AllocationState;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.server.StatsCollector;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
|
|
@ -175,6 +186,7 @@ import com.cloud.utils.db.SearchCriteria;
|
|||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
|
|
@ -243,6 +255,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
@Inject
|
||||
protected PrimaryDataStoreDao _storagePoolDao = null;
|
||||
@Inject
|
||||
protected ImageStoreDao _imageStoreDao = null;
|
||||
@Inject
|
||||
protected ImageStoreDetailsDao _imageStoreDetailsDao = null;
|
||||
@Inject
|
||||
protected SnapshotDataStoreDao _snapshotStoreDao = null;
|
||||
@Inject
|
||||
protected TemplateDataStoreDao _templateStoreDao = null;
|
||||
@Inject
|
||||
protected VolumeDataStoreDao _volumeStoreDao = null;
|
||||
@Inject
|
||||
protected CapacityDao _capacityDao;
|
||||
@Inject
|
||||
protected CapacityManager _capacityMgr;
|
||||
|
|
@ -1949,10 +1971,44 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
|
||||
return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
long storeId = cmd.getId();
|
||||
User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
|
||||
// Verify that image store exists
|
||||
ImageStoreVO store = _imageStoreDao.findById(storeId);
|
||||
if (store == null) {
|
||||
throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
|
||||
}
|
||||
_accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), store.getDataCenterId());
|
||||
|
||||
// Verify that there are no live snapshot, template, volume on the image store to be deleted
|
||||
List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listLiveByStoreId(storeId);
|
||||
if ( snapshots != null && snapshots.size() > 0 ){
|
||||
throw new CloudRuntimeException("Cannot delete image store with active snapshots backup!");
|
||||
}
|
||||
List<VolumeDataStoreVO> volumes = _volumeStoreDao.listLiveByStoreId(storeId);
|
||||
if ( volumes != null && volumes.size() > 0 ){
|
||||
throw new CloudRuntimeException("Cannot delete image store with active volumes backup!");
|
||||
}
|
||||
List<TemplateDataStoreVO> templates = _templateStoreDao.listLiveByStoreId(storeId);
|
||||
if ( templates != null && templates.size() > 0 ){
|
||||
throw new CloudRuntimeException("Cannot delete image store with active templates backup!");
|
||||
}
|
||||
|
||||
// ready to delete
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
// first delete from image_store_details table, we need to do that since we are not actually deleting record from main
|
||||
// image_data_store table, so delete cascade will not work
|
||||
_imageStoreDetailsDao.deleteDetails(storeId);
|
||||
_snapshotStoreDao.deletePrimaryRecordsForStore(storeId);
|
||||
_volumeStoreDao.deletePrimaryRecordsForStore(storeId);
|
||||
_templateStoreDao.deletePrimaryRecordsForStore(storeId);
|
||||
_imageStoreDao.remove(storeId);
|
||||
txn.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue