use of com.emc.storageos.systemservices.exceptions.CoordinatorClientException in project coprhd-controller by CoprHD.
the class UpgradeService method setTargetVersion.
/**
* Upgrade target version. Refer to product documentation for valid upgrade paths.
*
* @brief Update the target version of the build
* @param version The new version number
* @prereq Target version should be installed and cluster state should be STABLE
* @return Cluster state information.
* @throws IOException
*/
@PUT
@Path("target-version/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response setTargetVersion(@QueryParam("version") String version, @QueryParam("force") String forceUpgrade) throws IOException {
SoftwareVersion targetVersion = null;
try {
targetVersion = new SoftwareVersion(version);
} catch (InvalidSoftwareVersionException e) {
throw APIException.badRequests.parameterIsNotValid("version");
}
// validate
if (!_coordinator.isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
if (!_coordinator.isAllDatabaseServiceUp()) {
throw APIException.serviceUnavailable.databaseServiceNotAllUp();
}
// check if all DR sites are in stable or paused status
checkClusterState(true);
List<SoftwareVersion> available = null;
try {
available = _coordinator.getVersions(_coordinator.getMySvcId());
} catch (CoordinatorClientException e) {
throw APIException.internalServerErrors.getObjectFromError("available versions", "coordinator", e);
}
if (!available.contains(targetVersion)) {
throw APIException.badRequests.versionIsNotAvailableForUpgrade(version);
}
// To Do - add a check for upgradable from current
SoftwareVersion current = null;
try {
current = _coordinator.getRepositoryInfo(_coordinator.getMySvcId()).getCurrentVersion();
} catch (CoordinatorClientException e) {
throw APIException.internalServerErrors.getObjectFromError("current version", "coordinator", e);
}
if (!current.isSwitchableTo(targetVersion)) {
throw APIException.badRequests.versionIsNotUpgradable(targetVersion.toString(), current.toString());
}
// Check if allowed from upgrade voter and force option can veto
if (FORCE.equals(forceUpgrade)) {
_log.info("Force option supplied, skipping all geo/dr pre-checks");
} else {
for (UpgradeVoter voter : _upgradeVoters) {
voter.isOKForUpgrade(current.toString(), version);
}
}
try {
_coordinator.setTargetInfo(new RepositoryInfo(targetVersion, _coordinator.getTargetInfo(RepositoryInfo.class).getVersions()));
} catch (Exception e) {
throw APIException.internalServerErrors.setObjectToError("target version", "coordinator", e);
}
_log.info("target version changed successfully. new target {}", targetVersion);
auditUpgrade(OperationTypeEnum.UPDATE_VERSION, AuditLogManager.AUDITLOG_SUCCESS, null, targetVersion.toString(), FORCE.equals(forceUpgrade));
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
}
use of com.emc.storageos.systemservices.exceptions.CoordinatorClientException in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method setNodeGlobalScopeInfo.
public void setNodeGlobalScopeInfo(final CoordinatorSerializable info, final String siteId, final String kind, final String id) throws CoordinatorClientException {
if (info == null || kind == null) {
return;
}
try {
ConfigurationImpl cfg = new ConfigurationImpl();
cfg.setId(id);
// We can use service id as the "id" and the type of info as "kind", then we can persist certain type of info
cfg.setKind(kind);
// about a particular node in coordinator
cfg.setConfig(NODE_INFO, info.encodeAsString());
_coordinator.persistServiceConfiguration(siteId, cfg);
} catch (Exception e) {
_log.error("Failed to set node global scope info", e);
throw SyssvcException.syssvcExceptions.coordinatorClientError("Failed to set node global scope info. " + e.getMessage());
}
}
use of com.emc.storageos.systemservices.exceptions.CoordinatorClientException in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method removeTargetInfo.
/**
* Remove target info shared by all nodes.
* checkClusterUpgradable = true is used for rest api's. It forces to check the cluster state stable or not.
* checkClusterUpgradable = false will not check the cluster state. It is used when cluster is not in stable state,
* but we have to set target info at the same time.
*
* @param info
* @param checkClusterUpgradable
* @throws CoordinatorClientException
*/
public void removeTargetInfo(final CoordinatorSerializable info, boolean checkClusterUpgradable) throws CoordinatorClientException {
if (info == null) {
return;
}
final CoordinatorClassInfo coordinatorInfo = info.getCoordinatorClassInfo();
String id = coordinatorInfo.id;
String kind = coordinatorInfo.kind;
if (getTargetInfoLock()) {
try {
// check we are in stable state if checkState = true specified
if (checkClusterUpgradable && !isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
ConfigurationImpl cfg = new ConfigurationImpl();
cfg.setId(id);
cfg.setKind(kind);
cfg.setConfig(TARGET_INFO, info.encodeAsString());
_coordinator.removeServiceConfiguration(cfg);
_log.info("Target info removed: {}", info);
} catch (Exception e) {
throw SyssvcException.syssvcExceptions.coordinatorClientError("Failed to remove target info. " + e.getMessage());
} finally {
releaseTargetVersionLock();
}
} else {
throw SyssvcException.syssvcExceptions.coordinatorClientError("Failed to remove target info. Unable to obtain target lock");
}
}
use of com.emc.storageos.systemservices.exceptions.CoordinatorClientException in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method setTargetProperties.
/**
* Update system properties to zookeeper
*
* @param currentProps
* @throws CoordinatorClientException
*/
public void setTargetProperties(Map<String, String> currentProps) throws CoordinatorClientException {
Map<String, PropertyMetadata> propsMetadata = PropertiesMetadata.getGlobalMetadata();
// split properties as global, or site specific
HashMap<String, String> globalProps = new HashMap<String, String>();
HashMap<String, String> siteProps = new HashMap<String, String>();
for (Map.Entry<String, String> prop : currentProps.entrySet()) {
String key = prop.getKey();
PropertyMetadata metadata = propsMetadata.get(key);
if (metadata.getSiteSpecific()) {
siteProps.put(key, prop.getValue());
} else {
globalProps.put(key, prop.getValue());
}
}
// update properties to zk
if (getTargetInfoLock()) {
try {
// check we are in stable state if checkState = true specified
if (!isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
ConfigurationImpl globalCfg = new ConfigurationImpl();
globalCfg.setId(PropertyInfoExt.TARGET_PROPERTY_ID);
globalCfg.setKind(PropertyInfoExt.TARGET_PROPERTY);
PropertyInfoExt globalPropInfo = new PropertyInfoExt(globalProps);
globalCfg.setConfig(TARGET_INFO, globalPropInfo.encodeAsString());
_coordinator.persistServiceConfiguration(globalCfg);
_log.info("target properties changed successfully. target properties {}", globalPropInfo.toString());
if (siteProps.size() > 0) {
setSiteSpecificProperties(siteProps, _coordinator.getSiteId());
_log.info("site scope target properties changed successfully. target properties {}", siteProps.toString());
}
} catch (Exception e) {
throw SyssvcException.syssvcExceptions.coordinatorClientError("Failed to set target info. " + e.getMessage());
} finally {
releaseTargetVersionLock();
}
} else {
throw SyssvcException.syssvcExceptions.coordinatorClientError("Failed to set target state. Unable to obtain target lock");
}
}
use of com.emc.storageos.systemservices.exceptions.CoordinatorClientException in project coprhd-controller by CoprHD.
the class AbstractManager method resetTargetPowerOffState.
/**
* Reset target power off state back to NONE
*/
protected void resetTargetPowerOffState() {
poweroffAgreementsKeeper = new HashSet<String>();
while (true) {
try {
if (coordinator.isControlNode()) {
try {
coordinator.setTargetInfo(new PowerOffState(PowerOffState.State.NONE), false);
log.info("Step2: Target poweroff state change to: {}", PowerOffState.State.NONE);
} catch (CoordinatorClientException e) {
log.info("Step2: Wait another control node to set target poweroff state");
retrySleep();
}
} else {
log.info("Wait control node to set target poweroff state");
retrySleep();
}
// exit only when target poweroff state is NONE
if (coordinator.getTargetInfo(PowerOffState.class).getPowerOffState() == PowerOffState.State.NONE) {
break;
}
} catch (Exception e) {
retrySleep();
log.info("reset cluster poweroff state retrying. {}", e);
}
}
}
Aggregations