Remove State from image_store db table, and removed enableImageStore

api.
This commit is contained in:
Min Chen 2013-04-09 15:38:33 -07:00
parent 2a177de2bc
commit b2d5535bba
18 changed files with 3 additions and 250 deletions

View File

@ -21,10 +21,6 @@ import org.apache.cloudstack.api.InternalIdentity;
public interface ImageStore extends Identity, InternalIdentity {
public enum State {
Disabled, Enabled, Deactivated;
}
/**
* @return name of the object store.
@ -36,10 +32,6 @@ public interface ImageStore extends Identity, InternalIdentity {
*/
Long getDataCenterId();
/**
* @return image store state.
*/
State getState();
/**
* @return object store provider name

View File

@ -23,7 +23,6 @@ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaint
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.EnableImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
import com.cloud.exception.DiscoveryException;
@ -92,5 +91,4 @@ public interface StorageService{
ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
ImageStore enableImageStore(EnableImageStoreCmd cmd);
}

View File

@ -50,20 +50,6 @@ public class AddSecondaryStorageCmd extends BaseCmd {
description="the Zone ID for the secondary storage")
private Long zoneId;
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.UUID, entityType=RegionResponse.class,
description="the Region ID for the secondary storage")
private Long regionId;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the secondary storage data store")
private Map details;
@Parameter(name=ApiConstants.SCOPE, type=CommandType.STRING,
required=false, description="the scope of the secondary storage data store: zone or region or global")
private String scope;
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING,
required=false, description="the secondary storage store provider name")
private String imageProviderName;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -77,22 +63,6 @@ public class AddSecondaryStorageCmd extends BaseCmd {
return zoneId;
}
public Long getRegionId() {
return regionId;
}
public Map getDetails() {
return details;
}
public String getScope() {
return this.scope;
}
public String getImageProviderName() {
return this.imageProviderName;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -32,7 +32,7 @@ import com.cloud.exception.DiscoveryException;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "addImageStore", description="Adds backup image store.", responseObject=ImageStoreResponse.class)
@APICommand(name = "addImageStore", description="Adds backup image store.", responseObject=ImageStoreResponse.class, since = "4.2.0")
public class AddImageStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName());
private static final String s_name = "addimagestoreresponse";

View File

@ -29,7 +29,7 @@ import org.apache.log4j.Logger;
import com.cloud.user.Account;
@APICommand(name = "deleteImageStore", description = "Deletes an image store .", responseObject = SuccessResponse.class)
@APICommand(name = "deleteImageStore", description = "Deletes an image store .", responseObject = SuccessResponse.class, since = "4.2.0")
public class DeleteImageStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeleteImageStoreCmd.class.getName());

View File

@ -1,89 +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.api.command.admin.storage;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.region.RegionService;
import org.apache.log4j.Logger;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "enableImageStore", description="Enable an image store", responseObject=ImageStoreResponse.class)
public class EnableImageStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(EnableImageStoreCmd.class.getName());
private static final String s_name = "enableimagestoreresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=ImageStoreResponse.class,
description="Image Store id")
private Long id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="Enables specified image store.")
private String storeName;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
public String getStoreName() {
return storeName;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
ImageStore result = _storageService.enableImageStore(this);
if (result != null){
ImageStoreResponse response = _responseGenerator.createImageStoreResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable image store");
}
}
}

View File

@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
@APICommand(name = "listImageStores", description="Lists image stores.", responseObject=ImageStoreResponse.class)
@APICommand(name = "listImageStores", description="Lists image stores.", responseObject=ImageStoreResponse.class, since = "4.2.0")
public class ListImageStoresCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListImageStoresCmd.class.getName());
@ -43,9 +43,6 @@ public class ListImageStoresCmd extends BaseListCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the image store")
private String storeName;
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="the image store state")
private String state;
@Parameter(name=ApiConstants.PROTOCOL, type=CommandType.STRING, description="the image store protocol")
private String protocol;
@ -74,10 +71,6 @@ public class ListImageStoresCmd extends BaseListCmd {
return storeName;
}
public String getState() {
return state;
}
public String getProtocol() {
return protocol;
}

View File

@ -39,10 +39,6 @@ public class ImageStoreResponse extends BaseResponse {
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name of the image store")
private String zoneName;
@SerializedName("state") @Param(description="the state of the image store")
private ImageStore.State state;
@SerializedName("name") @Param(description="the name of the image store")
private String name;
@ -95,15 +91,6 @@ public class ImageStoreResponse extends BaseResponse {
this.zoneName = zoneName;
}
public ImageStore.State getState() {
return state;
}
public void setState(ImageStore.State state) {
this.state = state;
}
public String getName() {
return name;
}

View File

@ -23,5 +23,4 @@ import com.cloud.utils.db.GenericDao;
public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
public ImageStoreVO findByName(String name);
public ImageStoreVO findEnabledStore();
}

View File

@ -60,10 +60,6 @@ public class ImageStoreVO implements ImageStore {
@Column(name = "data_center_id")
private long dcId;
@Column(name = "state")
@Enumerated(value = EnumType.STRING)
private State state;
@Column(name = "scope")
@Enumerated(value = EnumType.STRING)
private ScopeType scope;
@ -150,14 +146,6 @@ public class ImageStoreVO implements ImageStore {
this.removed = removed;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
}

View File

@ -36,7 +36,6 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.cloudstack.storage.image.ImageStoreDriver;
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
import com.cloud.storage.ImageStore;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.storage.encoding.EncodingType;
@ -154,10 +153,6 @@ public class ImageStoreImpl implements ImageStoreEntity {
return imageDataStoreVO.getDataCenterId();
}
@Override
public ImageStore.State getState() {
return imageDataStoreVO.getState();
}
@Override
public String getProviderName() {

View File

@ -52,7 +52,6 @@ public class ImageStoreHelper {
store.setScope((ScopeType)params.get("scope"));
store.setUuid((String)params.get("uuid"));
store.setUrl((String)params.get("url"));
store.setState(ImageStore.State.Disabled);
store = imageStoreDao.persist(store);
return store;
}
@ -69,7 +68,6 @@ public class ImageStoreHelper {
store.setScope((ScopeType)params.get("scope"));
store.setUuid((String)params.get("uuid"));
store.setUrl((String)params.get("url"));
store.setState(ImageStore.State.Disabled);
store = imageStoreDao.persist(store);
// persist details

View File

@ -43,7 +43,6 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
private static final Logger s_logger = Logger.getLogger(ImageStoreDaoImpl.class);
private SearchBuilder<ImageStoreVO> nameSearch;
private SearchBuilder<ImageStoreVO> enableSearch;
@Override
@ -54,11 +53,6 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
nameSearch.and("name", nameSearch.entity().getName(), SearchCriteria.Op.EQ);
nameSearch.done();
enableSearch = createSearchBuilder();
enableSearch.and("state", enableSearch.entity().getState(), SearchCriteria.Op.EQ);
enableSearch.done();
return true;
}
@ -69,13 +63,5 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
return findOneBy(sc);
}
@Override
public ImageStoreVO findEnabledStore() {
SearchCriteria<ImageStoreVO> sc = nameSearch.create();
sc.setParameters("state", ImageStore.State.Enabled); // only one image store is enabled at one time.
return findOneBy(sc);
}
}

View File

@ -1931,15 +1931,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
Object name = cmd.getStoreName();
String provider = cmd.getProvider();
String protocol = cmd.getProtocol();
ImageStore.State state = null;
String stateStr = cmd.getState();
if (stateStr != null) {
try {
state = Enum.valueOf(ImageStore.State.class, stateStr.toUpperCase());
} catch (Exception e) {
throw new InvalidParameterValueException("invalid state" + stateStr);
}
}
Object keyword = cmd.getKeyword();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
@ -1953,7 +1944,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
sb.and("protocol", sb.entity().getProtocol(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ);
@ -1982,9 +1972,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
if (provider != null) {
sc.setParameters("provider", provider);
}
if (state != null) {
sc.setParameters("state", state);
}
if (protocol != null) {
sc.setParameters("protocol", protocol);
}

View File

@ -76,7 +76,6 @@ public class ImageStoreJoinDaoImpl extends GenericDaoBase<ImageStoreJoinVO, Long
osResponse.setScope(ids.getScope());
osResponse.setZoneId(ids.getZoneUuid());
osResponse.setZoneName(ids.getZoneName());
osResponse.setState(ids.getState());
String detailName = ids.getDetailName();
if ( detailName != null && detailName.length() > 0 ){

View File

@ -68,9 +68,6 @@ public class ImageStoreJoinVO extends BaseViewVO implements InternalIdentity, Id
@Column(name="data_center_name")
private String zoneName;
@Column(name="state")
private ImageStore.State state;
@Column(name="detail_name")
private String detailName;
@ -159,15 +156,6 @@ public class ImageStoreJoinVO extends BaseViewVO implements InternalIdentity, Id
this.scope = scope;
}
public ImageStore.State getState() {
return state;
}
public void setState(ImageStore.State state) {
this.state = state;
}
public void setName(String name) {
this.name = name;
}

View File

@ -45,7 +45,6 @@ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaint
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.EnableImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@ -2013,40 +2012,5 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
return true;
}
@Override
public ImageStore enableImageStore(EnableImageStoreCmd cmd) {
Long storeId = cmd.getId();
String storeName = cmd.getStoreName();
ImageStore store = null;
if ( storeId != null ){
store = _imageStoreDao.findById(storeId);
} else if ( storeName != null ){
store = _imageStoreDao.findByName(storeName);
} else {
throw new InvalidParameterValueException("Either image store id or name has to be specified!");
}
if (store == null) {
throw new InvalidParameterValueException("Unable to find image store by id: " + storeId + " OR by name: " + storeName);
}
// disable currently active store
ImageStoreVO activeStore = _imageStoreDao.findEnabledStore();
ImageStoreVO activeStoreForUpdate = _imageStoreDao.createForUpdate();
activeStoreForUpdate.setState(ImageStore.State.Disabled);
if ( !_imageStoreDao.update(activeStore.getId(), activeStoreForUpdate)){
throw new CloudRuntimeException("Failed to disable current active image store " + activeStore.getName());
}
ImageStoreVO storeForUpdate = _imageStoreDao.createForUpdate();
storeForUpdate.setState(ImageStore.State.Enabled);
if (_imageStoreDao.update(store.getId(), storeForUpdate)){
return _imageStoreDao.findById(store.getId());
}
else{
throw new CloudRuntimeException("Failed to enable image store by id: " + storeId + " OR by name: " + storeName);
}
}
}

View File

@ -77,7 +77,6 @@ CREATE TABLE `cloud`.`image_store` (
`data_center_id` bigint unsigned COMMENT 'datacenter id of data store',
`scope` varchar(255) COMMENT 'scope of data store',
`uuid` varchar(255) COMMENT 'uuid of data store',
`state` varchar(30) COMMENT 'state of data store',
`created` datetime COMMENT 'date the image store first signed on',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY(`id`)
@ -103,7 +102,6 @@ CREATE VIEW `cloud`.`image_store_view` AS
image_store.protocol,
image_store.url,
image_store.scope,
image_store.state,
data_center.id data_center_id,
data_center.uuid data_center_uuid,
data_center.name data_center_name,