use of com.emc.storageos.coordinator.client.service.DrUtil in project coprhd-controller by CoprHD.
the class ControlService method recoveryPrecheck.
@GET
@Path("cluster/recovery/precheck-status")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public RecoveryPrecheckStatus recoveryPrecheck() {
RecoveryPrecheckStatus recoveryPrecheckStatus = new RecoveryPrecheckStatus();
DrUtil drUtil = new DrUtil(_coordinator.getCoordinatorClient());
if (drUtil.isMultivdc() || drUtil.isMultisite()) {
recoveryPrecheckStatus.setStatus(RecoveryPrecheckStatus.Status.VAPP_IN_DR_OR_GEO);
return recoveryPrecheckStatus;
}
ArrayList<String> nodeList = _coordinator.getAllNodeIds();
HashSet<String> unvaliableNodeSet = new HashSet<>();
ArrayList<String> recoverableNodeList = new ArrayList<>();
for (String nodeId : nodeList) {
Long dbOfflineTime = DbInfoUtils.getDbOfflineTime(_coordinator.getCoordinatorClient(), Constants.DBSVC_NAME, nodeId);
if (dbOfflineTime != null) {
unvaliableNodeSet.add(nodeId);
} else {
dbOfflineTime = DbInfoUtils.getDbOfflineTime(_coordinator.getCoordinatorClient(), Constants.GEODBSVC_NAME, nodeId);
if (dbOfflineTime != null) {
unvaliableNodeSet.add(nodeId);
}
}
try {
DbOfflineStatus dbOfflineStatus = SysClientFactory.getSysClient(_coordinator.getNodeEndpoint(nodeId)).get(SysClientFactory.URI_GET_DB_OFFLINE_STATUS, DbOfflineStatus.class, null);
if (dbOfflineStatus.getOutageTimeExceeded()) {
recoverableNodeList.add(nodeId);
unvaliableNodeSet.add(nodeId);
}
} catch (Exception e) {
recoveryPrecheckStatus.setStatus(RecoveryPrecheckStatus.Status.NODE_UNREACHABLE);
_log.warn("Failed to check dbOfflineStatus on {} :{}", nodeId, e.getMessage());
}
}
ArrayList<String> unvaliableNodeList = new ArrayList<>(unvaliableNodeSet);
setRecoverPrecheckStatus(recoveryPrecheckStatus, unvaliableNodeList, recoverableNodeList, nodeList.size());
recoveryPrecheckStatus.setUnavailables(unvaliableNodeList);
recoveryPrecheckStatus.setRecoverables(recoverableNodeList);
return recoveryPrecheckStatus;
}
use of com.emc.storageos.coordinator.client.service.DrUtil in project coprhd-controller by CoprHD.
the class StorageDriverService method precheckForEnv.
protected void precheckForEnv() {
DrUtil drUtil = new DrUtil(coordinator);
if (!drUtil.isActiveSite()) {
throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed("This operation is not allowed on standby site");
}
for (Site site : drUtil.listSites()) {
SiteState siteState = site.getState();
if (!siteState.equals(SiteState.ACTIVE) && !siteState.equals(SiteState.STANDBY_SYNCED)) {
throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed(String.format("Site %s is in %s state,not active or synced", site.getName(), siteState));
}
ClusterInfo.ClusterState state = coordinator.getControlNodesState(site.getUuid());
if (state != ClusterInfo.ClusterState.STABLE) {
throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed(String.format("Currently site %s is not stable", site.getName()));
}
}
// driver operations and order executions to avoid impact on each other.
if (hasOngoingQueuedOrders()) {
throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed("There are ongoing or queued orders now, please wait until these orders complete");
}
}
use of com.emc.storageos.coordinator.client.service.DrUtil in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method setUp.
@Before
public void setUp() throws Exception {
Constructor constructor = ProductName.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
ProductName productName = (ProductName) constructor.newInstance();
productName.setName("vipr");
SoftwareVersion version = new SoftwareVersion("vipr-2.4.0.0.100");
LinkedList<SoftwareVersion> available = new LinkedList<SoftwareVersion>();
available.add(version);
RepositoryInfo repositoryInfo = new RepositoryInfo(new SoftwareVersion("vipr-2.4.0.0.100"), available);
standby = new SiteConfigRestRep();
standby.setClusterStable(true);
standby.setFreshInstallation(true);
standby.setDbSchemaVersion("2.4");
standby.setSoftwareVersion("vipr-2.4.0.0.150");
standby.setHostIPv4AddressMap(new HashMap<String, String>());
standby.getHostIPv4AddressMap().put("vipr1", "10.247.101.100");
// setup standby site
standbySite1 = new Site();
standbySite1.setUuid("site-uuid-1");
standbySite1.setVip("10.247.101.110");
standbySite1.getHostIPv4AddressMap().put("vipr1", "10.247.101.111");
standbySite1.getHostIPv4AddressMap().put("vipr2", "10.247.101.112");
standbySite1.getHostIPv4AddressMap().put("vipr3", "10.247.101.113");
standbySite1.setState(SiteState.STANDBY_PAUSED);
standbySite1.setVdcShortId("vdc1");
standbySite1.setNodeCount(1);
standbySite2 = new Site();
standbySite2.setUuid("site-uuid-2");
standbySite2.setState(SiteState.STANDBY_SYNCED);
standbySite2.setVdcShortId("vdc1");
standbySite2.setVip("10.247.101.158");
standbySite2.setNodeCount(1);
standbySite3 = new Site();
standbySite3.setUuid("site-uuid-3");
standbySite3.setVdcShortId("fake-vdc-id");
standbySite3.setState(SiteState.ACTIVE);
standbySite3.setVdcShortId("vdc1");
standbySite3.setNodeCount(1);
primarySite = new Site();
primarySite.setUuid("primary-site-uuid");
primarySite.setVip("127.0.0.1");
primarySite.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
primarySite.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
primarySite.setVdcShortId("vdc1");
primarySite.setState(SiteState.ACTIVE);
primarySite.setNodeCount(3);
// mock DBClient
dbClientMock = mock(DbClientImpl.class);
// mock coordinator client
coordinator = mock(CoordinatorClient.class);
// mock ipsecconfig
IPsecConfig ipsecConfig = mock(IPsecConfig.class);
doReturn("ipsec-preshared-key").when(ipsecConfig).getPreSharedKey();
drUtil = mock(DrUtil.class);
natCheckParam = new DRNatCheckParam();
apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
try {
KeyGenerator keyGenerator = null;
keyGenerator = KeyGenerator.getInstance("HmacSHA256");
secretKey = keyGenerator.generateKey();
} catch (NoSuchAlgorithmException e) {
fail("generate key fail");
}
drService = spy(new DisasterRecoveryService());
drService.setDbClient(dbClientMock);
drService.setCoordinator(coordinator);
drService.setDrUtil(drUtil);
drService.setSiteMapper(new SiteMapper());
drService.setSysUtils(new SysUtils());
drService.setIpsecConfig(ipsecConfig);
drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
standbyConfig = new Site();
standbyConfig.setUuid("standby-site-uuid-1");
standbyConfig.setVip(standbySite1.getVip());
standbyConfig.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
standbyConfig.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
standbyConfig.setNodeCount(3);
doReturn(standbyConfig.getUuid()).when(coordinator).getSiteId();
Configuration config = new ConfigurationImpl();
config.setConfig(Constants.CONFIG_DR_ACTIVE_SITEID, primarySite.getUuid());
doReturn(config).when(coordinator).queryConfiguration(Constants.CONFIG_DR_ACTIVE_KIND, Constants.CONFIG_DR_ACTIVE_ID);
doReturn("2.4").when(coordinator).getCurrentDbSchemaVersion();
doReturn(primarySite.getUuid()).when(coordinator).getSiteId();
doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState();
// Don't need to record audit log in UT
doNothing().when(drService).auditDisasterRecoveryOps(any(OperationTypeEnum.class), anyString(), anyString(), anyVararg());
doReturn(repositoryInfo).when(coordinator).getTargetInfo(RepositoryInfo.class);
doReturn(standbySite1).when(drUtil).getSiteFromLocalVdc(standbySite1.getUuid());
doReturn(standbySite2).when(drUtil).getSiteFromLocalVdc(standbySite2.getUuid());
doThrow(CoordinatorException.retryables.cannotFindSite(NONEXISTENT_ID)).when(drUtil).getSiteFromLocalVdc(NONEXISTENT_ID);
doReturn(primarySite).when(drUtil).getSiteFromLocalVdc(primarySite.getUuid());
SiteNetworkState siteNetworkState = new SiteNetworkState();
siteNetworkState.setNetworkHealth(SiteNetworkState.NetworkHealth.GOOD);
doReturn(siteNetworkState).when(drUtil).getSiteNetworkState(any(String.class));
CoordinatorClientInetAddressMap addressMap = new CoordinatorClientInetAddressMap();
addressMap.setDualInetAddress(DualInetAddress.fromAddresses("10.247.101.110", ""));
doReturn(addressMap).when(coordinator).getInetAddessLookupMap();
InterProcessLock lock = mock(InterProcessLock.class);
doReturn(lock).when(coordinator).getLock(anyString());
doReturn(true).when(lock).acquire(anyInt(), any(TimeUnit.class));
doNothing().when(lock).release();
}
use of com.emc.storageos.coordinator.client.service.DrUtil 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.service.DrUtil in project coprhd-controller by CoprHD.
the class InternalDbClient method start.
@Override
public synchronized void start() {
super.start();
drUtil = new DrUtil(this.getCoordinatorClient());
}
Aggregations