use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DrPostFailoverHandler method run.
/**
* Run the handler. The handler runs only on single node. If it fails, current service should quit and another node takes over to retry
*/
public void run() {
try {
SiteState siteState = drUtil.getLocalSite().getState();
if (!siteState.equals(SiteState.STANDBY_FAILING_OVER)) {
log.info("Ignore DR post failover handler for site state {}", siteState);
return;
}
log.info("Acquiring lock {}", POST_FAILOVER_HANDLER_LOCK);
InterProcessLock lock = coordinator.getLock(POST_FAILOVER_HANDLER_LOCK);
lock.acquire();
log.info("Acquired lock {}", POST_FAILOVER_HANDLER_LOCK);
try {
// check site state again after acquiring lock
Site site = drUtil.getLocalSite();
siteState = site.getState();
if (!siteState.equals(SiteState.STANDBY_FAILING_OVER)) {
log.info("Ignore DR post failover handler for site state {}", siteState);
return;
}
boolean isExecuted = isCompleted();
if (!isExecuted) {
log.info("Start post failover processing {}", name);
updateStatus(Status.EXECUTING);
execute();
updateStatus(Status.COMPLETED);
} else {
log.info("Handler {} was completed on other node", name);
}
if (isAllHandlersCompleted()) {
log.info("All handlers successfully completed. Change site state to ACTIVE");
site.setState(SiteState.ACTIVE);
coordinator.persistServiceConfiguration(site.toConfiguration());
}
} finally {
lock.release();
log.info("Released lock {}", POST_FAILOVER_HANDLER_LOCK);
}
} catch (Exception e) {
log.error("Failed to execute DR failover handler", e);
throw new IllegalStateException(e);
}
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DrUtil method getDROperationLock.
/**
* @param checkAllSitesOperations
* @return DR operation lock only when successfully acquired lock and there's no ongoing DR operation, throw Exception otherwise
*/
public InterProcessLock getDROperationLock(boolean checkAllSitesOperations) {
// Try to acquire lock, succeed or throw Exception
InterProcessLock lock = coordinator.getLock(DR_OPERATION_LOCK);
boolean acquired;
try {
acquired = lock.acquire(LOCK_WAIT_TIME_SEC, TimeUnit.SECONDS);
} catch (Exception e) {
try {
lock.release();
} catch (Exception ex) {
log.error("Fail to release DR operation lock", ex);
}
throw APIException.internalServerErrors.failToAcquireDROperationLock();
}
if (!acquired) {
throw APIException.internalServerErrors.failToAcquireDROperationLock();
}
// Has successfully acquired lock
if (!checkAllSitesOperations) {
return lock;
}
// Check if there's ongoing DR operation on any site, if there is, release lock and throw exception
Site ongoingSite = null;
List<Site> sites = listSites();
for (Site site : sites) {
if (site.getState().isDROperationOngoing()) {
ongoingSite = site;
break;
}
}
if (ongoingSite != null) {
try {
lock.release();
} catch (Exception e) {
log.error("Fail to release DR operation lock", e);
}
throw APIException.internalServerErrors.concurrentDROperationNotAllowed(ongoingSite.getName(), ongoingSite.getState().toString());
}
return lock;
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DrUtil method listSites.
/**
* List all sites in given vdc
*
* @return list of all sites
*/
public List<Site> listSites(String vdcShortId) {
List<Site> result = new ArrayList<>();
String siteKind = String.format("%s/%s", Site.CONFIG_KIND, vdcShortId);
for (Configuration siteConfig : coordinator.queryAllConfiguration(siteKind)) {
result.add(new Site(siteConfig));
}
return result;
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method getControlNodesState.
/**
* Get all control nodes' state
*
* @param targetGiven
* target repository
* @param infos
* control nodes' repository
* @param targetPropertiesGiven
* target property
* @param configVersions
* control nodes' configVersions
* @param targetPowerOffState
* target poweroff state
* @param targetDrivers
* target driver list
* @param drivers
* control nodes' driver lists
* @param siteId
* @return Control nodes' state
*/
private ClusterInfo.ClusterState getControlNodesState(final RepositoryInfo targetGiven, final Map<Service, RepositoryInfo> infos, final PropertyInfoRestRep targetPropertiesGiven, final Map<Service, ConfigVersion> configVersions, final Map<Service, VdcConfigVersion> vdcConfigVersions, final PowerOffState targetPowerOffState, final StorageDriversInfo targetDrivers, final Map<Service, StorageDriversInfo> drivers, String siteId) {
if (targetGiven == null || targetPropertiesGiven == null || targetPowerOffState == null) {
// only for first time target initializing
return ClusterInfo.ClusterState.INITIALIZING;
}
DrUtil drUtil = new DrUtil(this);
Site site = drUtil.getSiteFromLocalVdc(siteId);
SiteState siteState = site.getState();
int siteNodeCount = site.getNodeCount();
if (infos == null || infos.size() != siteNodeCount || configVersions == null || configVersions.size() != siteNodeCount) {
return ClusterInfo.ClusterState.DEGRADED;
}
if (siteState == SiteState.STANDBY_ERROR) {
log.info("Control nodes' state DEGRADED since DR site state is STANDBY_ERROR");
return ClusterInfo.ClusterState.DEGRADED;
}
// 1st. Find nodes which currents and versions are different from target's
List<String> differentCurrents = getDifferentCurrentsCommon(targetGiven, infos);
List<String> differentVersions = getDifferentVersionsCommon(targetGiven, infos);
// 2nd. Find nodes which configVersions are different from target's
// Note : we use config version to judge if properties on a node are sync-ed with target's.
List<String> differentConfigVersions = getDifferentConfigVersionCommon(targetPropertiesGiven, configVersions);
List<String> differentVdcConfigVersions = getDifferentVdcConfigVersionCommon(vdcConfigVersions);
if (targetPowerOffState.getPowerOffState() != PowerOffState.State.NONE) {
log.info("Control nodes' state POWERINGOFF");
return ClusterInfo.ClusterState.POWERINGOFF;
} else if (!differentConfigVersions.isEmpty()) {
log.info("Control nodes' state UPDATING: {}", Strings.repr(targetPropertiesGiven));
return ClusterInfo.ClusterState.UPDATING;
} else if (!differentVdcConfigVersions.isEmpty()) {
log.info("Control nodes' state UPDATING vdc config version: {}", Strings.repr(differentVdcConfigVersions));
return ClusterInfo.ClusterState.UPDATING;
} else if (siteState.isDROperationOngoing()) {
log.info("Control nodes' state UPDATING since DR operation ongoing: {}", siteState);
return ClusterInfo.ClusterState.UPDATING;
} else if (!isControlNodesDriversSynced(targetDrivers, drivers)) {
log.info("Control nodes' state UPDATING since not all nodes' drivers are synced with target");
return ClusterInfo.ClusterState.UPDATING;
} else if (differentCurrents.isEmpty() && differentVersions.isEmpty()) {
// check for the extra upgrading states
if (isDbSchemaVersionChanged()) {
MigrationStatus status = getMigrationStatus();
if (status == null) {
log.info("Control nodes state is UPGRADING_PREP_DB ");
return ClusterInfo.ClusterState.UPGRADING_PREP_DB;
}
log.info("Control nodes state is {}", status);
switch(status) {
case RUNNING:
return ClusterInfo.ClusterState.UPGRADING_CONVERT_DB;
case FAILED:
return ClusterInfo.ClusterState.UPGRADING_FAILED;
case DONE:
break;
default:
log.error("The current db schema version doesn't match the target db schema version, " + "but the current migration status is {} ", status);
}
}
log.info("Control nodes' state STABLE");
return ClusterInfo.ClusterState.STABLE;
} else if (differentCurrents.isEmpty()) {
log.info("Control nodes' state SYNCING: {}", Strings.repr(differentVersions));
return ClusterInfo.ClusterState.SYNCING;
} else if (differentVersions.isEmpty()) {
log.info("Control nodes' state UPGRADING: {}", Strings.repr(differentCurrents));
return ClusterInfo.ClusterState.UPGRADING;
} else {
log.error("Control nodes' in an UNKNOWN state. Target given: {} {}", targetGiven, Strings.repr(infos));
return ClusterInfo.ClusterState.UNKNOWN;
}
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class ConnectVdcTaskOp method sendVdcNodeCheckRequest.
/**
* Send node check request to target vdc.
*
* @param vdcProp vdc to send msg to
* @param vdcsToCheck list of vdc's with nodes to check
* @return
* @throws Exception
*/
private VdcNodeCheckResponse sendVdcNodeCheckRequest(Properties vdcProp, Collection<VirtualDataCenter> vdcsToCheck) {
List<VdcConfig> virtualDataCenters = new ArrayList<VdcConfig>();
for (VirtualDataCenter vdc : vdcsToCheck) {
VdcConfig vdcConfig = new VdcConfig();
Site activeSite = drUtil.getActiveSite(vdc.getShortId());
vdcConfig.setId(vdc.getId());
vdcConfig.setShortId(vdc.getShortId());
if (activeSite.getHostIPv4AddressMap() != null && !activeSite.getHostIPv4AddressMap().isEmpty() && activeSite.isUsingIpv4()) {
HashMap<String, String> ipv4AddrMap = new HashMap<String, String>(activeSite.getHostIPv4AddressMap());
vdcConfig.setHostIPv4AddressesMap(ipv4AddrMap);
} else if (activeSite.getHostIPv6AddressMap() != null && !activeSite.getHostIPv6AddressMap().isEmpty()) {
HashMap<String, String> ipv6AddrMap = new HashMap<String, String>(activeSite.getHostIPv6AddressMap());
vdcConfig.setHostIPv6AddressesMap(ipv6AddrMap);
} else {
throw GeoException.fatals.cannotPerformOperation(vdc.getId().toString(), " no nodes were found on VirtualDataCenter object");
}
virtualDataCenters.add(vdcConfig);
}
return sendVdcNodeCheckRequest(vdcProp, virtualDataCenters);
}
Aggregations