use of com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus in project coprhd-controller by CoprHD.
the class VirtualDataCenterService method removeVirtualDataCenter.
/**
* Remove Virtual Data Center
*
* @param id
* @brief Delete a VDC
* @return TaskResourceRep
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SECURITY_ADMIN }, blockProxies = true)
public TaskResourceRep removeVirtualDataCenter(@PathParam("id") URI id) {
blockRoot();
ArgValidator.checkFieldUriType(id, VirtualDataCenter.class, "id");
VirtualDataCenter vdc = queryResource(id);
ConnectionStatus status = vdc.getConnectionStatus();
if (BooleanUtils.isTrue(vdc.getLocal())) {
throw APIException.badRequests.cantChangeConnectionStatusOfLocalVDC();
}
if (status.equals(ConnectionStatus.CONNECT_FAILED)) {
_log.error("Cannot delete {}. Mannual VDC recovery required", vdc.getShortId());
throw APIException.methodNotAllowed.notSupported();
}
// TODO Need to check that VDC to be removed is not "local VDC".
// We can not remove local VDC.
// TODO: Are there more pre-checks we want to do synchronously?
auditOp(OperationTypeEnum.REMOVE_VDC, true, null, vdc.getLabel(), vdc.getApiEndpoint());
return enqueueJob(vdc, JobType.VDC_REMOVE_JOB);
}
use of com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus in project coprhd-controller by CoprHD.
the class VirtualDataCenterService method updateVirtualDataCenter.
/**
* Update Virtual Data Center
*
* @param id
* @param param
* @brief Change properties of a VDC
* @return TaskResourceRep
*/
@PUT
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public TaskResourceRep updateVirtualDataCenter(@PathParam("id") URI id, VirtualDataCenterModifyParam param) {
ArgValidator.checkFieldUriType(id, VirtualDataCenter.class, "id");
String localVdcId = VdcUtil.getLocalVdc().getId().toString();
if (!id.toString().equalsIgnoreCase(localVdcId)) {
blockRoot();
}
VirtualDataCenter vdc = queryResource(id);
if (StringUtils.isNotEmpty(param.getName()) && !param.getName().equals(vdc.getLabel())) {
checkForDuplicateName(param.getName(), VirtualDataCenter.class);
}
/*
* If vdc is in failed state:
* CONNECT_FAILED
* REMOVE_FAILED
*
* Stop this request. (CTRL-3883)
*/
// CTRL-3883 update should fail if previous op failed
ConnectionStatus status = vdc.getConnectionStatus();
_log.info("Updating VDC {}, connection status {}", vdc.getShortId(), status);
if (status.equals(VirtualDataCenter.ConnectionStatus.CONNECT_FAILED) || status.equals(VirtualDataCenter.ConnectionStatus.REMOVE_FAILED)) {
_log.error("Cannot update VDC {} if it's in a failed state. Mannual VDC recovery required", vdc.getShortId());
throw APIException.methodNotAllowed.notSupported();
}
List<Object> params = new ArrayList<>();
params.add(modifyVirtualDataCenterInfo(VdcUtil.getLocalVdc(), vdc, param, null));
auditOp(OperationTypeEnum.UPDATE_VDC, true, null, id.toString());
return enqueueJob(vdc, JobType.VDC_UPDATE_JOB, params);
}
use of com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus in project coprhd-controller by CoprHD.
the class ConnectVdcTaskOp method preSteps.
/**
* PreSteps to be executed before initial connect vdc operation
*/
private void preSteps() {
// Check & verify connection status of my current vdc
ConnectionStatus status = myVdc.getConnectionStatus();
switch(status) {
case ISOLATED:
// current status is isolated, not connected with others, generate the inter-vdc secure key of my current vdc
SecretKey key = apiSignatureGenerator.getSignatureKey(SignatureKeyType.INTERVDC_API);
myVdc.setSecretKey(new String(Base64.encodeBase64(key.getEncoded()), Charset.forName("UTF-8")));
dbClient.updateAndReindexObject(myVdc);
break;
case CONNECTED:
// getAllConnectedVdc
if (getAllVdc().size() < 2) {
String errMsg = "incorrect connected vdc count";
log.error(errMsg);
throw GeoException.fatals.connectVdcPrecheckFail(myVdcId, errMsg);
}
// verify my secure key still valid
break;
default:
String errMsg = "Unexpected local vdc connection status";
log.error(errMsg);
throw GeoException.fatals.connectVdcPrecheckFail(myVdcId, errMsg);
}
}
use of com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus in project coprhd-controller by CoprHD.
the class InternalDbClient method shouldCheckDbStatus.
/**
* Check if we need wait for geodbsvc up on given vdc
*/
private boolean shouldCheckDbStatus(VirtualDataCenter vdc) {
// local vdc is always connected with itself
if (vdc.getLocal()) {
return true;
}
// incomplete vdc record
if (vdc.getShortId() == null) {
log.error("invalid record in db status check {}", vdc.getId());
return false;
}
ConnectionStatus connStatus = vdc.getConnectionStatus();
GeoReplicationStatus repStatus = vdc.getRepStatus();
log.info("vdc connectionStatus {} repStatus {}", connStatus, repStatus);
// geodb connected
if (repStatus.equals(GeoReplicationStatus.REP_ALL)) {
log.info("vdc {}, repStatus {}", vdc.getId(), repStatus);
return true;
}
// connecting now, check db stable status as well
if (connStatus.equals(ConnectionStatus.CONNECTING_SYNCED)) {
return true;
}
return false;
}
use of com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus in project coprhd-controller by CoprHD.
the class VdcConfigHelper method syncVdcConfig.
public void syncVdcConfig(List<VdcConfig> newVdcConfigList, String assignedVdcId, boolean isRecover, Long vdcConfigVersion, String ipsecKey) {
boolean vdcConfigChanged = false;
// query existing vdc list from db
// The new queryByType method returns an iterative list, convert it to a "real"
// list first
List<URI> vdcIdList = new ArrayList<URI>();
for (URI vdcId : dbClient.queryByType(VirtualDataCenter.class, true)) {
vdcIdList.add(vdcId);
}
// vdc that are going to be removed from local db
for (VdcConfig config : newVdcConfigList) {
if (vdcIdList.contains(config.getId())) {
vdcIdList.remove(config.getId());
mergeVdcConfig(config, isRecover);
} else {
// not contains in vdcIdList - it is a new vdc and we should insert to db
VirtualDataCenter newVdc = fromConfigParam(config);
if (config.getId().toString().equals(assignedVdcId)) {
newVdc.setLocal(true);
}
dbClient.createObject(newVdc);
if (newVdc.getLocal()) {
VdcUtil.invalidateVdcUrnCache();
}
createVdcConfigInZk(config, ipsecKey);
vdcConfigChanged = true;
if (newVdc.getLocal()) {
drUtil.setLocalVdcShortId(newVdc.getShortId());
}
}
}
// check vdc that are going to be removed
ArrayList<String> obsoletePeers = new ArrayList<String>();
for (URI removeVdcId : vdcIdList) {
log.warn("vdc config {} is being removed", removeVdcId);
VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, removeVdcId);
ConnectionStatus connStatus = vdc.getConnectionStatus();
if (!isRecover && connStatus.equals(ConnectionStatus.CONNECT_FAILED)) {
log.info("Ignore vdc record {} with status {}", removeVdcId, connStatus);
continue;
}
dbClient.markForDeletion(vdc);
Map<String, String> addressesMap = dbClient.queryHostIPAddressesMap(vdc);
if (!addressesMap.isEmpty()) {
// obsolete peers ip in cassandra system table
obsoletePeers.addAll(addressesMap.values());
log.info("add {} peers to obsolete list", addressesMap.size());
}
dbClient.removeVdcNodesFromBlacklist(vdc);
deleteVdcConfigFromZk(vdc);
vdcConfigChanged = true;
}
if (!obsoletePeers.isEmpty()) {
// update peer ip to ZK so that geodbsvc could get it
notifyDbSvcWithObsoleteCassandraPeers(Constants.GEODBSVC_NAME, obsoletePeers);
log.info("notify geodbsvc with {} obsolete cassandra peers", obsoletePeers.size());
}
if (assignedVdcId != null) {
// Persist a flag to notify geodbsvc on all the nodes in the current vdc
log.info("reset db needed, set the flag for all db to look it up");
updateDbSvcConfig(Constants.GEODBSVC_NAME, Constants.REINIT_DB, String.valueOf(true));
}
if (vdcConfigChanged) {
String action = SiteInfo.GEO_OP_CONFIG_CHANGE;
// loses connection with other nodes
if (assignedVdcId != null) {
action = SiteInfo.IPSEC_OP_ROTATE_KEY;
}
triggerVdcConfigUpdate(vdcConfigVersion, action);
}
}
Aggregations