mirror of https://github.com/apache/cloudstack.git
Add ListImageStoresCmd api.
This commit is contained in:
parent
a872d6d306
commit
848fea6069
|
|
@ -0,0 +1,111 @@
|
|||
// 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 org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ClusterResponse;
|
||||
import org.apache.cloudstack.api.response.ImageStoreResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.PodResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.async.AsyncJob;
|
||||
|
||||
@APICommand(name = "listImageStores", description="Lists image stores.", responseObject=ImageStoreResponse.class)
|
||||
public class ListImageStoresCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListImageStoresCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listimagestoreresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@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;
|
||||
|
||||
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING, description="the image store provider")
|
||||
private String provider;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
|
||||
description="the Zone ID for the image store")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = StoragePoolResponse.class,
|
||||
description="the ID of the storage pool")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
ListResponse<ImageStoreResponse> response = _queryService.searchForImageStores(this);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ package org.apache.cloudstack.query;
|
|||
|
||||
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
|
|
@ -40,6 +41,7 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
|||
import org.apache.cloudstack.api.response.DomainRouterResponse;
|
||||
import org.apache.cloudstack.api.response.EventResponse;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.api.response.ImageStoreResponse;
|
||||
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||
|
|
@ -88,6 +90,8 @@ public interface QueryService {
|
|||
|
||||
public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsCmd cmd);
|
||||
|
||||
public ListResponse<ImageStoreResponse> searchForImageStores(ListImageStoresCmd cmd);
|
||||
|
||||
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd);
|
||||
|
||||
public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd);
|
||||
|
|
|
|||
|
|
@ -243,6 +243,10 @@ listS3s=1
|
|||
|
||||
#### image store commands
|
||||
addImageStore=1
|
||||
listImageStores=1
|
||||
deleteImageStore=1
|
||||
enableImageStore=1
|
||||
|
||||
|
||||
#### host commands
|
||||
addHost=3
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
@Override
|
||||
public ImageStoreResponse createImageStoreResponse(ImageStore os) {
|
||||
List<ImageStoreJoinVO> viewStores = ApiDBUtils.newImageStoreView(os);
|
||||
List<ImageStoreResponse> listStores = ViewResponseHelper.createObjectStoreResponse(viewStores.toArray(new ImageStoreJoinVO[viewStores.size()]));
|
||||
List<ImageStoreResponse> listStores = ViewResponseHelper.createImageStoreResponse(viewStores.toArray(new ImageStoreJoinVO[viewStores.size()]));
|
||||
assert listStores != null && listStores.size() == 1 : "There should be one image data store returned";
|
||||
return listStores.get(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import javax.naming.ConfigurationException;
|
|||
|
||||
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
|
|
@ -51,6 +52,7 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
|||
import org.apache.cloudstack.api.response.DomainRouterResponse;
|
||||
import org.apache.cloudstack.api.response.EventResponse;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.api.response.ImageStoreResponse;
|
||||
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||
|
|
@ -74,6 +76,7 @@ import com.cloud.api.query.dao.DataCenterJoinDao;
|
|||
import com.cloud.api.query.dao.DiskOfferingJoinDao;
|
||||
import com.cloud.api.query.dao.DomainRouterJoinDao;
|
||||
import com.cloud.api.query.dao.HostJoinDao;
|
||||
import com.cloud.api.query.dao.ImageStoreJoinDao;
|
||||
import com.cloud.api.query.dao.InstanceGroupJoinDao;
|
||||
import com.cloud.api.query.dao.ProjectAccountJoinDao;
|
||||
import com.cloud.api.query.dao.ProjectInvitationJoinDao;
|
||||
|
|
@ -92,6 +95,7 @@ import com.cloud.api.query.vo.DiskOfferingJoinVO;
|
|||
import com.cloud.api.query.vo.DomainRouterJoinVO;
|
||||
import com.cloud.api.query.vo.EventJoinVO;
|
||||
import com.cloud.api.query.vo.HostJoinVO;
|
||||
import com.cloud.api.query.vo.ImageStoreJoinVO;
|
||||
import com.cloud.api.query.vo.InstanceGroupJoinVO;
|
||||
import com.cloud.api.query.vo.ProjectAccountJoinVO;
|
||||
import com.cloud.api.query.vo.ProjectInvitationJoinVO;
|
||||
|
|
@ -126,6 +130,8 @@ import com.cloud.projects.dao.ProjectDao;
|
|||
import com.cloud.server.Criteria;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
|
|
@ -228,6 +234,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||
@Inject
|
||||
private StoragePoolJoinDao _poolJoinDao;
|
||||
|
||||
@Inject
|
||||
private ImageStoreJoinDao _imageStoreJoinDao;
|
||||
|
||||
@Inject
|
||||
private DiskOfferingJoinDao _diskOfferingJoinDao;
|
||||
|
||||
|
|
@ -1843,7 +1852,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||
SearchBuilder<StoragePoolJoinVO> sb = _poolJoinDao.createSearchBuilder();
|
||||
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -1867,7 +1876,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||
}
|
||||
|
||||
if (name != null) {
|
||||
sc.setParameters("name", "%" + name + "%");
|
||||
sc.setParameters("name", name);
|
||||
}
|
||||
|
||||
if (path != null) {
|
||||
|
|
@ -1904,6 +1913,101 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ListResponse<ImageStoreResponse> searchForImageStores(ListImageStoresCmd cmd) {
|
||||
Pair<List<ImageStoreJoinVO>, Integer> result = searchForImageStoresInternal(cmd);
|
||||
ListResponse<ImageStoreResponse> response = new ListResponse<ImageStoreResponse>();
|
||||
|
||||
List<ImageStoreResponse> poolResponses = ViewResponseHelper.createImageStoreResponse(result.first().toArray(new ImageStoreJoinVO[result.first().size()]));
|
||||
response.setResponses(poolResponses, result.second());
|
||||
return response;
|
||||
}
|
||||
|
||||
private Pair<List<ImageStoreJoinVO>, Integer> searchForImageStoresInternal(ListImageStoresCmd cmd) {
|
||||
|
||||
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
|
||||
Object id = cmd.getId();
|
||||
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();
|
||||
|
||||
|
||||
Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
|
||||
|
||||
SearchBuilder<ImageStoreJoinVO> sb = _imageStoreJoinDao.createSearchBuilder();
|
||||
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
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);
|
||||
|
||||
|
||||
SearchCriteria<ImageStoreJoinVO> sc = sb.create();
|
||||
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<ImageStoreJoinVO> ssc = _imageStoreJoinDao.createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("provider", SearchCriteria.Op.LIKE, "%" + keyword + "%" );
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
sc.setParameters("id", id);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
sc.setParameters("name", name);
|
||||
}
|
||||
|
||||
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
}
|
||||
if (provider != null) {
|
||||
sc.setParameters("provider", provider);
|
||||
}
|
||||
if (state != null) {
|
||||
sc.setParameters("state", state);
|
||||
}
|
||||
if (protocol != null) {
|
||||
sc.setParameters("protocol", protocol);
|
||||
}
|
||||
|
||||
// search Store details by ids
|
||||
Pair<List<ImageStoreJoinVO>, Integer> uniqueStorePair = _imageStoreJoinDao.searchAndCount(sc, searchFilter);
|
||||
Integer count = uniqueStorePair.second();
|
||||
if (count.intValue() == 0) {
|
||||
// empty result
|
||||
return uniqueStorePair;
|
||||
}
|
||||
List<ImageStoreJoinVO> uniqueStores = uniqueStorePair.first();
|
||||
Long[] vrIds = new Long[uniqueStores.size()];
|
||||
int i = 0;
|
||||
for (ImageStoreJoinVO v : uniqueStores) {
|
||||
vrIds[i++] = v.getId();
|
||||
}
|
||||
List<ImageStoreJoinVO> vrs = _imageStoreJoinDao.searchByIds(vrIds);
|
||||
return new Pair<List<ImageStoreJoinVO>, Integer>(vrs, count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd) {
|
||||
Pair<List<DiskOfferingJoinVO>, Integer> result = searchForDiskOfferingsInternal(cmd);
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ public class ViewResponseHelper {
|
|||
return new ArrayList<StoragePoolResponse>(vrDataList.values());
|
||||
}
|
||||
|
||||
public static List<ImageStoreResponse> createObjectStoreResponse(ImageStoreJoinVO... stores) {
|
||||
public static List<ImageStoreResponse> createImageStoreResponse(ImageStoreJoinVO... stores) {
|
||||
Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<Long, ImageStoreResponse>();
|
||||
// Initialise the vrdatalist with the input data
|
||||
for (ImageStoreJoinVO vr : stores) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue