use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method getTargetInfo.
private <T extends CoordinatorSerializable> T getTargetInfo(String siteId, final Class<T> clazz, String id, String kind) throws CoordinatorException {
T info;
try {
info = clazz.newInstance();
} catch (Exception e) {
log.error("Failed to create instance according class {}, {}", clazz, e);
throw CoordinatorException.fatals.unableToCreateInstanceOfTargetInfo(clazz.getName(), e);
}
final Configuration config = queryConfiguration(siteId, kind, id);
if (config != null && config.getConfig(TARGET_INFO) != null) {
final String infoStr = config.getConfig(TARGET_INFO);
log.debug("getTargetInfo({}): info={}", clazz.getName(), Strings.repr(infoStr));
final T decodeInfo = info.decodeFromString(infoStr);
log.debug("getTargetInfo({}): info={}", clazz.getName(), decodeInfo);
return decodeInfo;
}
return null;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method getPropertyInfo.
/**
* Get property
*
* This method gets target properties from coordinator service as a string
* and merges it with the defaults and the ovf properties
* Syssvc is responsible for publishing the target property information into coordinator
*
* @return property object
* @throws CoordinatorException
*/
@Override
public PropertyInfo getPropertyInfo() throws CoordinatorException {
PropertyInfo info = new PropertyInfo();
Map<String, String> defaults = new HashMap<String, String>((Map) defaultProperties);
final Configuration config = queryConfiguration(TARGET_PROPERTY, TARGET_PROPERTY_ID);
if (null == config || null == config.getConfig(TARGET_INFO)) {
log.debug("getPropertyInfo(): no properties saved in coordinator returning defaults");
info.setProperties(defaults);
} else {
final String infoStr = config.getConfig(TARGET_INFO);
try {
log.debug("getPropertyInfo(): properties saved in coordinator=" + Strings.repr(infoStr));
info.setProperties(mergeProps(defaults, decodeFromString(infoStr).getProperties()));
} catch (final Exception e) {
throw CoordinatorException.fatals.unableToDecodeDataFromCoordinator(e);
}
}
// add site specific properties
PropertyInfoExt siteScopePropInfo = getTargetInfo(getSiteId(), PropertyInfoExt.class);
if (siteScopePropInfo != null) {
info.getProperties().putAll(siteScopePropInfo.getProperties());
}
// add the ovf properties
info.getProperties().putAll((Map) ovfProperties);
return info;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method persistServiceConfiguration.
@Override
public void persistServiceConfiguration(String siteId, Configuration... configs) throws CoordinatorException {
try {
for (Configuration config : configs) {
String configParentPath = getKindPath(siteId, config.getKind());
EnsurePath path = new EnsurePath(configParentPath);
path.ensure(_zkConnection.curator().getZookeeperClient());
String servicePath = String.format("%1$s/%2$s", configParentPath, config.getId());
Stat stat = _zkConnection.curator().checkExists().forPath(servicePath);
CuratorTransaction handler = zkTransactionHandler.get();
if (stat != null) {
if (handler != null) {
CuratorTransactionFinal tx = handler.setData().forPath(servicePath, config.serialize()).and();
zkTransactionHandler.set(tx);
} else {
_zkConnection.curator().setData().forPath(servicePath, config.serialize());
}
} else {
if (handler != null) {
CuratorTransactionFinal tx = handler.create().forPath(servicePath, config.serialize()).and();
zkTransactionHandler.set(tx);
} else {
_zkConnection.curator().create().forPath(servicePath, config.serialize());
}
}
}
} catch (final Exception e) {
log.error("Failed to persist service configuration e=", e);
throw CoordinatorException.fatals.unableToPersistTheConfiguration(e);
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method queryAllConfiguration.
@Override
public List<Configuration> queryAllConfiguration(String siteId, String kind) throws CoordinatorException {
String serviceParentPath = getKindPath(siteId, kind);
List<String> configPaths;
try {
configPaths = _zkConnection.curator().getChildren().forPath(serviceParentPath);
} catch (KeeperException.NoNodeException ignore) {
// Ignore exception, don't re-throw
log.debug("Caught exception but ignoring it: " + ignore);
return Arrays.asList(new Configuration[0]);
} catch (Exception e) {
throw CoordinatorException.fatals.unableToListAllConfigurationForKind(kind, e);
}
List<Configuration> configs = new ArrayList<Configuration>(configPaths.size());
for (String configPath : configPaths) {
Configuration config = queryConfiguration(siteId, kind, configPath);
if (config != null) {
configs.add(config);
}
}
return configs;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class SetupUtils method isSetupComplete.
public static boolean isSetupComplete() {
if (StorageOsPlugin.isEnabled()) {
CoordinatorClient coordinatorClient = StorageOsPlugin.getInstance().getCoordinatorClient();
Configuration setupConfig = coordinatorClient.queryConfiguration(CONFIG_KIND, CONFIG_ID);
complete = (setupConfig != null) && StringUtils.equals(setupConfig.getConfig(COMPLETE), Boolean.TRUE.toString());
} else // In Dev mode we don't have coordinator so assume always setup
if (Play.mode.isDev()) {
complete = true;
} else {
complete = false;
}
return complete;
}
Aggregations