-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change storage pool scope from Cluster to Zone and vise versa #8875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
f7ea076
d6aa362
5a1e7bd
5bd6995
c5cbd5d
0fab7a3
283db1f
fb976d9
042aef7
72160ea
abf7082
5ba040d
ca36119
962d0f3
f98b754
3753be3
30d628d
aa83ec0
dcb9449
8ce579a
bc4e700
d714b8c
8de7aa6
4b07a6c
b3245cd
f3bdae8
9657a10
8d36db0
5ef41e1
aad87f2
85a6340
49341db
419e5a4
d611198
9da8382
8646c80
35c8b00
ba397d7
81a2c67
c502838
edea352
3af24b4
cc08595
0b75de1
eedb361
e62551b
57c4a2f
271d526
0821cc7
0507508
afd107b
2bdd974
e40c14a
e0cec9e
11b43b2
25c4a01
1b698c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // 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.BaseAsyncCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.ClusterResponse; | ||
| import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
|
|
||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.storage.StorageService; | ||
|
|
||
| @APICommand(name = "changeStoragePoolScope", description = "Changes the scope of a storage pool.", responseObject = SuccessResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
abh1sar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class ChangeStoragePoolScopeCmd extends BaseAsyncCmd { | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StoragePoolResponse.class, required = true, description = "the Id of the storage pool") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.SCOPE, type = CommandType.STRING, required = true, description = "the scope of the storage: cluster or zone") | ||
| private String scope; | ||
|
|
||
| @Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "the CLuster ID to use for the storage pool's scope") | ||
abh1sar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private Long clusterId; | ||
|
|
||
| @Inject | ||
| public StorageService _storageService; | ||
abh1sar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public String getEventType() { | ||
| return EventTypes.EVENT_CHANGE_STORAGE_POOL_SCOPE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| return "Change Storage Pool Scope"; | ||
abh1sar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| boolean result = _storageService.changeStoragePoolScope(this); | ||
| if (result) { | ||
| SuccessResponse response = new SuccessResponse(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } else { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update storage pool"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccountId(); | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getScope() { | ||
| return scope; | ||
| } | ||
|
|
||
| public Long getClusterId() { | ||
| return clusterId; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,16 @@ | |
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
| import javax.inject.Inject; | ||
|
|
||
| import org.apache.commons.collections.CollectionUtils; | ||
| import org.apache.log4j.Logger; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.host.HostVO; | ||
| import com.cloud.host.dao.HostDao; | ||
| import com.cloud.hypervisor.Hypervisor.HypervisorType; | ||
| import com.cloud.server.ResourceTag.ResourceObjectType; | ||
| import com.cloud.storage.ScopeType; | ||
|
|
@@ -45,13 +48,17 @@ | |
| import com.cloud.utils.db.DB; | ||
| import com.cloud.utils.db.GenericDaoBase; | ||
| import com.cloud.utils.db.GenericSearchBuilder; | ||
| import com.cloud.utils.db.JoinBuilder.JoinType; | ||
| import com.cloud.utils.db.SearchBuilder; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
| import com.cloud.utils.db.SearchCriteria.Func; | ||
| import com.cloud.utils.db.SearchCriteria.Op; | ||
| import com.cloud.utils.db.TransactionLegacy; | ||
| import com.cloud.utils.db.UpdateBuilder; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import com.cloud.vm.VMInstanceVO; | ||
| import com.cloud.vm.VirtualMachine; | ||
| import com.cloud.vm.dao.VMInstanceDao; | ||
|
|
||
| @Component | ||
| public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements VolumeDao { | ||
|
|
@@ -72,8 +79,14 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol | |
| protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch2; | ||
| protected GenericSearchBuilder<VolumeVO, SumCount> secondaryStorageSearch; | ||
| private final SearchBuilder<VolumeVO> poolAndPathSearch; | ||
| protected SearchBuilder<VolumeVO> volumePoolNotInClusterSearch; | ||
|
|
||
| @Inject | ||
| ResourceTagDao _tagsDao; | ||
| @Inject | ||
| HostDao _hostDao; | ||
| @Inject | ||
| VMInstanceDao _vmDao; | ||
|
||
|
|
||
| protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?"; | ||
| // need to account for zone-wide primary storage where storage_pool has | ||
|
|
@@ -493,7 +506,19 @@ public VolumeDaoImpl() { | |
| poolAndPathSearch.and("poolId", poolAndPathSearch.entity().getPoolId(), Op.EQ); | ||
| poolAndPathSearch.and("path", poolAndPathSearch.entity().getPath(), Op.EQ); | ||
| poolAndPathSearch.done(); | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void init() { | ||
| volumePoolNotInClusterSearch = createSearchBuilder(); | ||
| volumePoolNotInClusterSearch.and("poolId", volumePoolNotInClusterSearch.entity().getPoolId(), Op.EQ); | ||
| SearchBuilder<VMInstanceVO> vmSearch = _vmDao.createSearchBuilder(); | ||
| vmSearch.and("vmStateSearch", vmSearch.entity().getState(), Op.IN); | ||
| SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder(); | ||
| hostSearch.and("clusterId", hostSearch.entity().getClusterId(), SearchCriteria.Op.NEQ); | ||
| vmSearch.join("hostSearch", hostSearch, hostSearch.entity().getId(), vmSearch.entity().getHostId(), JoinType.INNER); | ||
| volumePoolNotInClusterSearch.join("vmSearch", vmSearch, vmSearch.entity().getId(), volumePoolNotInClusterSearch.entity().getInstanceId(), JoinType.INNER); | ||
| volumePoolNotInClusterSearch.done(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -841,4 +866,13 @@ public List<VolumeVO> listByIds(List<Long> ids) { | |
| sc.setParameters("idIN", ids.toArray()); | ||
| return listBy(sc, null); | ||
| } | ||
|
|
||
| @Override | ||
| public List<VolumeVO> listByPoolIdVMStatesNotInCluster(long clusterId, List<VirtualMachine.State> states, long poolId) { | ||
| SearchCriteria<VolumeVO> sc = volumePoolNotInClusterSearch.create(); | ||
| sc.setParameters("poolId", poolId); | ||
| sc.setParameters("states", states); | ||
abh1sar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sc.setJoinParameters("hostSearch", "clusterId", clusterId); | ||
| return listBy(sc, null); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.