Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
1 change: 1 addition & 0 deletions 1 api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ public class EventTypes {
// Primary storage pool
public static final String EVENT_ENABLE_PRIMARY_STORAGE = "ENABLE.PS";
public static final String EVENT_DISABLE_PRIMARY_STORAGE = "DISABLE.PS";
public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL";

// VPN
public static final String EVENT_REMOTE_ACCESS_VPN_CREATE = "VPN.REMOTE.ACCESS.CREATE";
Expand Down
3 changes: 3 additions & 0 deletions 3 api/src/main/java/com/cloud/storage/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.DeleteSecondaryStagingStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.SyncStoragePoolCmd;

import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InsufficientCapacityException;
Expand Down Expand Up @@ -104,4 +105,6 @@ public interface StorageService {

ImageStore updateImageStoreStatus(Long id, Boolean readonly);

StoragePool syncStoragePool(SyncStoragePoolCmd cmd);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 com.cloud.event.EventTypes;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.storage.StoragePool;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.context.CallContext;

import java.util.logging.Logger;

@APICommand(name = SyncStoragePoolCmd.APINAME,
description = "Sync storage pool with management server (currently supported for Datastore Cluster in VMware and syncs the datastores in it)",
responseObject = StoragePoolResponse.class,
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
since = "4.15.1",
authorized = {RoleType.Admin}
)
public class SyncStoragePoolCmd extends BaseAsyncCmd {

public static final String APINAME = "syncStoragePool";
public static final Logger LOGGER = Logger.getLogger(SyncStoragePoolCmd.class.getName());

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StoragePoolResponse.class, required = true, description = "Storage pool id")
private Long poolId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public Long getPoolId() {
return poolId;
}

@Override
public String getEventType() {
return EventTypes.EVENT_SYNC_STORAGE_POOL;
}

@Override
public String getEventDescription() {
return "Attempting to synchronise storage pool with management server";
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
StoragePool result = _storageService.syncStoragePool(this);
if (result != null) {
StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
response.setResponseName("storagepool");
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to synchronise storage pool");
}
}

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccountId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cloudstack.storage.command.IntroduceObjectCmd;
import org.apache.cloudstack.storage.command.ResignatureCommand;
import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand;
import org.apache.cloudstack.storage.command.SyncVolumePathCommand;

import com.cloud.agent.api.Answer;

Expand Down Expand Up @@ -81,5 +82,7 @@ public interface StorageProcessor {

Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd);

public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd);
public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd);

public Answer syncVolumePath(SyncVolumePathCommand cmd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.cloudstack.storage.command.ResignatureCommand;
import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.cloudstack.storage.command.SyncVolumePathCommand;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
Expand Down Expand Up @@ -73,7 +74,9 @@ public Answer handleStorageCommands(StorageSubSystemCommand command) {
} else if (command instanceof DirectDownloadCommand) {
return processor.handleDownloadTemplateToPrimaryStorage((DirectDownloadCommand) command);
} else if (command instanceof CheckDataStoreStoragePolicyComplainceCommand) {
return processor.CheckDataStoreStoragePolicyComplaince((CheckDataStoreStoragePolicyComplainceCommand) command);
return processor.checkDataStoreStoragePolicyCompliance((CheckDataStoreStoragePolicyComplainceCommand) command);
} else if (command instanceof SyncVolumePathCommand) {
return processor.syncVolumePath((SyncVolumePathCommand) command);
}

return new Answer((Command)command, false, "not implemented yet");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// 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.command;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.to.DiskTO;

public class SyncVolumePathAnswer extends Answer {
private DiskTO disk;

public SyncVolumePathAnswer() {
super(null);
}

public SyncVolumePathAnswer(DiskTO disk) {
super(null);
setDisk(disk);
}

public SyncVolumePathAnswer(String errMsg) {
super(null, false, errMsg);
}

public DiskTO getDisk() {
return disk;
}

public void setDisk(DiskTO disk) {
this.disk = disk;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// 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.command;

import com.cloud.agent.api.to.DiskTO;

public class SyncVolumePathCommand extends StorageSubSystemCommand {

private DiskTO disk;

public SyncVolumePathCommand(final DiskTO disk) {
super();
this.disk = disk;
}

public DiskTO getDisk() {
return disk;
}

public void setDisk(final DiskTO disk) {
this.disk = disk;
}

@Override
public boolean executeInSequence() {
return false;
}

@Override
public void setExecuteInSequence(boolean inSeq) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.math.BigDecimal;
import java.util.List;

import com.cloud.agent.api.ModifyStoragePoolAnswer;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
import org.apache.cloudstack.framework.config.ConfigKey;
Expand Down Expand Up @@ -240,4 +241,6 @@ public interface StorageManager extends StorageService {

boolean isStoragePoolDatastoreClusterParent(StoragePool pool);

void syncDatastoreClusterStoragePool(long datastoreClusterPoolId, List<ModifyStoragePoolAnswer> childDatastoreAnswerList, long hostId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface StoragePoolHostDao extends GenericDao<StoragePoolHostVO, Long>

List<StoragePoolHostVO> listByHostStatus(long poolId, Status hostStatus);

List<Long> findHostsConnectedToPools(List<Long> poolIds);

List<Pair<Long, Integer>> getDatacenterStoragePoolHostInfo(long dcId, boolean sharedOnly);

public void deletePrimaryRecordsForHost(long hostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
Expand All @@ -44,6 +44,8 @@ public class StoragePoolHostDaoImpl extends GenericDaoBase<StoragePoolHostVO, Lo

protected static final String HOST_FOR_POOL_SEARCH = "SELECT * FROM storage_pool_host_ref ph, host h where ph.host_id = h.id and ph.pool_id=? and h.status=? ";

protected static final String HOSTS_FOR_POOLS_SEARCH = "SELECT DISTINCT(ph.host_id) FROM storage_pool_host_ref ph, host h WHERE ph.host_id = h.id AND h.status = 'Up' AND resource_state = 'Enabled' AND ph.pool_id IN (?)";

protected static final String STORAGE_POOL_HOST_INFO = "SELECT p.data_center_id, count(ph.host_id) " + " FROM storage_pool p, storage_pool_host_ref ph "
+ " WHERE p.id = ph.pool_id AND p.data_center_id = ? " + " GROUP by p.data_center_id";

Expand Down Expand Up @@ -121,6 +123,33 @@ public List<StoragePoolHostVO> listByHostStatus(long poolId, Status hostStatus)
return result;
}

@Override
public List<Long> findHostsConnectedToPools(List<Long> poolIds) {
List<Long> hosts = new ArrayList<Long>();
if (poolIds == null || poolIds.isEmpty()) {
return hosts;
}

String poolIdsInStr = poolIds.stream().map(poolId -> String.valueOf(poolId)).collect(Collectors.joining(",", "(", ")"));
String sql = HOSTS_FOR_POOLS_SEARCH.replace("(?)", poolIdsInStr);

TransactionLegacy txn = TransactionLegacy.currentTxn();
try(PreparedStatement pstmt = txn.prepareStatement(sql);) {
try(ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) {
long hostId = rs.getLong(1); // host_id column
hosts.add(hostId);
}
} catch (SQLException e) {
s_logger.warn(String.format("Unable to retrieve hosts from pools [%s] due to [%s].", poolIdsInStr, e.getMessage()));
}
} catch (Exception e) {
s_logger.warn(String.format("Unable to retrieve hosts from pools [%s] due to [%s].", poolIdsInStr, e.getMessage()));
}

return hosts;
}

@Override
public List<Pair<Long, Integer>> getDatacenterStoragePoolHostInfo(long dcId, boolean sharedOnly) {
ArrayList<Pair<Long, Integer>> l = new ArrayList<Pair<Long, Integer>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {

Integer countAll();

List<StoragePoolVO> findPoolsByStorageType(String storageType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public PrimaryDataStoreDaoImpl() {
AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ);
AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ);
AllFieldSearch.and("storage_provider_name", AllFieldSearch.entity().getStorageProviderName(), Op.EQ);
AllFieldSearch.and("poolType", AllFieldSearch.entity().getPoolType(), Op.EQ);
AllFieldSearch.done();

DcPodSearch = createSearchBuilder();
Expand Down Expand Up @@ -581,4 +582,11 @@ public List<StoragePoolVO> findPoolsInClusters(List<Long> clusterIds) {
sc.setParameters("status", StoragePoolStatus.Up);
return listBy(sc);
}

@Override
public List<StoragePoolVO> findPoolsByStorageType(String storageType) {
SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
sc.setParameters("poolType", storageType);
return listBy(sc);
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.