use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorConfigStoringHelper method createOrUpdateConfig.
/**
* Creates or updates a new entry of the specified type in coordinator. If siteId
* is not null, the config is in zk site specific area. Otherwise in global area
*
* @param objToPersist
* the object to store in coordinator
* @param lockName
* the name of the lock to use while storing this object
* If passed as Null, lock is assumed to be already owned
* @param configKInd
* @param configId
* @param ConfigKey
* @throws Exception
*/
public void createOrUpdateConfig(Object objToPersist, String lockName, String siteId, String configKInd, String configId, String ConfigKey) throws Exception {
InterProcessLock lock = acquireLock(lockName);
try {
if (lock != null) {
Configuration config = coordinator.queryConfiguration(siteId, configKInd, configId);
ConfigurationImpl configImpl = null;
if (config == null) {
configImpl = new ConfigurationImpl();
configImpl.setId(configId);
configImpl.setKind(configKInd);
log.debug("Creating new config");
} else {
configImpl = (ConfigurationImpl) config;
if (config.getKind() == null) {
((ConfigurationImpl) config).setKind(configKInd);
}
if (config.getId() == null) {
((ConfigurationImpl) config).setId(configId);
}
log.debug("Updating existing config");
}
configImpl.setConfig(ConfigKey, SerializerUtils.serializeAsBase64EncodedString(objToPersist));
coordinator.persistServiceConfiguration(siteId, configImpl);
log.debug("Updated config successfully");
}
} finally {
releaseLock(lock);
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorConfigStoringHelper method readAllConfigs.
/**
* Reads all objects of the specified kind from coordinator
*
* @param configKind
* @param configId
* @return the retrieved objects list or null if not found
* @throws ClassNotFoundException
* @throws IOException
*/
public <T> Map<String, T> readAllConfigs(String configKind, String configKey) throws IOException, ClassNotFoundException {
List<Configuration> configsList = coordinator.queryAllConfiguration(configKind);
Map<String, T> returnedObjects = new HashMap<String, T>();
if (CollectionUtils.isEmpty(configsList)) {
log.debug("No config of kind " + configKind + " found");
return returnedObjects;
}
for (Configuration config : configsList) {
String serializedConfig = config.getConfig(configKey);
if (serializedConfig != null) {
@SuppressWarnings("unchecked") T deserialize = (T) SerializerUtils.deserialize(serializedConfig);
returnedObjects.put(config.getId(), deserialize);
}
}
return returnedObjects;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class DbDowntimeTracker method updateTrackerInfo.
/**
* Update db offline event info in ZK.
*/
private void updateTrackerInfo(Site site, String serviceName, List<String> activeNodes) {
String siteId = site.getUuid();
log.info("Querying db tracker info from zk");
Configuration config = coordinator.getCoordinatorClient().queryConfiguration(siteId, Constants.DB_DOWNTIME_TRACKER_CONFIG, serviceName);
DbOfflineEventInfo dbOfflineEventInfo = new DbOfflineEventInfo(config);
log.debug("DbofflineEnventInfo is {}", dbOfflineEventInfo.getEventInfo());
long currentTimeStamp = TimeUtils.getCurrentTime();
Long lastUpdateTimestamp = dbOfflineEventInfo.getLastUpdateTimestamp();
long interval = 0L;
if (lastUpdateTimestamp != null) {
interval = Math.min((currentTimeStamp - lastUpdateTimestamp), TRACKER_CHECK_INTERVAL);
}
if (interval != 0L && interval < NO_NEED_UPDATE_LIMIT) {
log.info("Have already updated within a few minutes, skipping this update");
return;
}
dbOfflineEventInfo.setLastUpdateTimestamp(currentTimeStamp);
log.info(String.format("Db tracker last check time: %d, current check time: %d, site: %s", lastUpdateTimestamp, currentTimeStamp, siteId));
int nodeCount = site.getNodeCount();
for (int i = 1; i <= nodeCount; i++) {
String nodeId = "vipr" + i;
if (activeNodes.contains(nodeId)) {
dbOfflineEventInfo.setLastActiveTimestamp(nodeId, currentTimeStamp);
log.info(String.format("Service(%s) of node(%s) last active timestamp has been updated to %s", serviceName, nodeId, currentTimeStamp));
if (dbOfflineEventInfo.getOfflineTimeInMS(nodeId) != null) {
dbOfflineEventInfo.setOfflineTimeInMS(nodeId, null);
dbOfflineEventInfo.setKeyOfflineAlertInDay(nodeId, null);
log.info("Service({}) of node({}) is recovered", serviceName, nodeId);
}
} else {
Long lastOfflineInMS = dbOfflineEventInfo.getOfflineTimeInMS(nodeId);
lastOfflineInMS = (lastOfflineInMS == null) ? 0 : lastOfflineInMS;
long newOfflineTime = lastOfflineInMS + interval;
dbOfflineEventInfo.setOfflineTimeInMS(nodeId, newOfflineTime);
alertStatusCheck(nodeId, serviceName, dbOfflineEventInfo, newOfflineTime / TimeUtils.DAYS);
log.info(String.format("Service(%s) of node(%s) has been unavailable for %s mins", serviceName, nodeId, newOfflineTime / TimeUtils.MINUTES));
}
}
config = dbOfflineEventInfo.toConfiguration(serviceName);
coordinator.getCoordinatorClient().persistServiceConfiguration(siteId, config);
log.info("Persist db tracker info to zk successfully");
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class VdcManager method auditCompletedDrOperation.
/**
* Check if ongoing DR operation succeeded or failed, then record audit log accordingly and remove this operation record from ZK.
*/
private void auditCompletedDrOperation() {
if (!drUtil.isActiveSite()) {
return;
}
InterProcessLock lock = coordinator.getCoordinatorClient().getSiteLocalLock(AUDIT_DR_OPERATION_LOCK);
boolean hasLock = false;
try {
hasLock = lock.acquire(AUDIT_LOCK_WAIT_TIME_SEC, TimeUnit.SECONDS);
if (!hasLock) {
return;
}
log.info("Local site is active, local node acquired lock, starting audit complete DR operations ...");
List<Configuration> configs = coordinator.getCoordinatorClient().queryAllConfiguration(DrOperationStatus.CONFIG_KIND);
if (configs == null || configs.isEmpty()) {
return;
}
for (Configuration config : configs) {
DrOperationStatus operation = new DrOperationStatus(config);
String siteId = operation.getSiteUuid();
InterState interState = operation.getInterState();
Site site = null;
try {
site = drUtil.getSiteFromLocalVdc(siteId);
} catch (RetryableCoordinatorException e) {
// Under this situation, just record audit log and clear DR operation status
if (interState.equals(InterState.REMOVING_STANDBY) && e.getServiceCode() == ServiceCode.COORDINATOR_SITE_NOT_FOUND) {
this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, siteId);
coordinator.getCoordinatorClient().removeServiceConfiguration(config);
log.info("DR operation status has been cleared: {}", operation);
continue;
}
throw e;
}
SiteState currentState = site.getState();
if (currentState.equals(SiteState.STANDBY_ERROR)) {
// Failed
this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, site.toBriefString());
} else if (!currentState.isDROperationOngoing()) {
// Succeeded
this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, site.toBriefString());
} else {
// Still ongoing, do nothing
continue;
}
log.info(String.format("Site %s state has transformed from %s to %s", siteId, interState, currentState));
// clear this operation status
coordinator.getCoordinatorClient().removeServiceConfiguration(config);
log.info("DR operation status has been cleared: {}", operation);
}
} catch (Exception e) {
log.error("Auditing DR operation failed with exception", e);
} finally {
try {
if (hasLock) {
lock.release();
}
} catch (Exception e) {
log.error("Failed to release DR operation audit lock", e);
}
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class GeoSeedProviderImpl method getAllConfigZNodes.
private List<Configuration> getAllConfigZNodes() {
List<Configuration> configs = coordinator.queryAllConfiguration(coordinator.getSiteId(), Constants.GEODB_CONFIG);
List<Configuration> result = new ArrayList<>();
List<Configuration> leftoverConfig = coordinator.queryAllConfiguration(Constants.GEODB_CONFIG);
configs.addAll(leftoverConfig);
// filter out non config ZNodes: 2.0 and global
for (Configuration config : configs) {
if (isConfigZNode(config)) {
result.add(config);
}
}
return result;
}
Aggregations