use of com.emc.storageos.coordinator.client.model.PropertyInfoExt in project coprhd-controller by CoprHD.
the class ConfigService method getTargetPropsCommon.
/**
* Get target properties
*
* @param maskSecretsProperties whether secrets properties should be masked out
* @return target properties
*/
private PropertyInfoRestRep getTargetPropsCommon(boolean maskSecretsProperties) {
PropertyInfoExt targetPropInfo = new PropertyInfoExt();
try {
targetPropInfo.setProperties(mergeProps(getPropertiesDefaults(), getMutatedProps(maskSecretsProperties)));
targetPropInfo.getProperties().putAll(getPropertiesOvf());
} catch (Exception e) {
throw APIException.internalServerErrors.getObjectFromError("target property", "coordinator", e);
}
return new PropertyInfoRestRep(targetPropInfo.getAllProperties());
}
use of com.emc.storageos.coordinator.client.model.PropertyInfoExt in project coprhd-controller by CoprHD.
the class PropertyManager method initializeLocalAndTargetInfo.
/**
* Initialize local and target info
*
* @throws Exception
*/
private void initializeLocalAndTargetInfo(String svcId) throws Exception {
// publish config_version which is also a target property
// used as a flag denoting whether target properties have been changed
PropertyInfoExt localPropInfo = localRepository.getOverrideProperties();
localConfigVersion = localPropInfo.getProperty(PropertyInfoExt.CONFIG_VERSION);
if (localConfigVersion == null) {
localConfigVersion = "0";
localPropInfo.addProperty(PropertyInfoExt.CONFIG_VERSION, localConfigVersion);
}
coordinator.setNodeSessionScopeInfo(new ConfigVersion(localConfigVersion));
log.info("Step1a: Local config version: {}", localConfigVersion);
// get local target property info
localTargetPropInfo = getLocalTargetPropInfo(localPropInfo);
log.debug("Step1a: Local target properties: {}", localTargetPropInfo);
// set target if empty
targetPropInfo = coordinator.getTargetProperties();
if (targetPropInfo == null) {
// only control node can set target
try {
// Set the updated propperty info in coordinator
coordinator.setTargetProperties(localPropInfo.getAllProperties());
coordinator.setTargetInfo(new PowerOffState(PowerOffState.State.NONE));
targetPropInfo = coordinator.getTargetInfo(PropertyInfoExt.class);
log.info("Step1b: Target property set to local state: {}", targetPropInfo);
} catch (CoordinatorClientException e) {
log.info("Step1b: Wait another control node to set target");
retrySleep();
throw e;
}
}
}
use of com.emc.storageos.coordinator.client.model.PropertyInfoExt in project coprhd-controller by CoprHD.
the class LocalRepository method getControllerOvfProperties.
/**
* Get controller ovf properties
*
* @return PropertyInfo controller ovf properties
*/
public PropertyInfoExt getControllerOvfProperties() throws LocalRepositoryException {
final String prefix = "getControllerOvfProperties(): ";
_log.debug(prefix);
final String[] cmd = { _SYSTOOL_CMD, _SYSTOOL_GET_CONTROLLEROVFPROPS };
PropertyInfoExt overrides = new PropertyInfoExt(exec(prefix, cmd));
_log.debug(prefix + "properties={}", Strings.repr(overrides));
return overrides;
}
use of com.emc.storageos.coordinator.client.model.PropertyInfoExt in project coprhd-controller by CoprHD.
the class ClusterAddressPoller method getUpdatedDataNodeConfig.
public void getUpdatedDataNodeConfig() throws Exception {
if (getCoordinator().isControlNode()) {
return;
}
boolean bConnectCoordinator = false;
// check if lost connection to controller cluster's coordinator (nodes' address changed)
try {
bConnectCoordinator = getCoordinator().isConnected();
} catch (Exception e) {
bConnectCoordinator = false;
_log.error("Cannot access controller's coordinator: " + e.getMessage());
}
// if cannot connect to controller cluster's coordinator
if (!bConnectCoordinator) {
if (_lastVipSysClient == null) {
_log.error("Cannot connect to controller via cached vip or coordinator");
throw SyssvcException.syssvcExceptions.failConnectControllerError("Cannot connect to controller via coordinator or vip");
}
PropertyInfoRestRep rep = null;
try {
rep = _lastVipSysClient.post(SysClientFactory.URI_GET_PROPERTIES, PropertyInfoRestRep.class, "OVF");
} catch (Exception e) {
// now cannot access vip as well as cluster's coordinator
_log.error("Cannot connect to controller via coordinator, failed accessing last vip {}, {}", _lastVipSysClient.getServiceURI(), e);
throw e;
}
// try to get props cached locally
PropertyInfoExt localProps = null;
try {
localProps = getLocalRepository().getControllerOvfProperties();
} catch (LocalRepositoryException e) {
_log.error("Failed to get controller properties from local repository");
throw e;
}
// Check if controller nodes' address changed
Map<String, String> nodeDiffProps = checkNodeAddressDiff(localProps, rep);
if (nodeDiffProps.size() > 0) {
try {
setLocalRepoControllerProps(nodeDiffProps);
_log.info("rebooting to get updated cluster addresses");
getLocalRepository().reboot();
} catch (Exception e) {
_log.error("Reboot failed, ", e);
throw e;
}
}
return;
}
// Now data node can connect to cluster's coordinator, check if vip changed or not
PropertyInfoRestRep rep = null;
if (_lastVipSysClient != null) {
try {
rep = _lastVipSysClient.post(SysClientFactory.URI_GET_PROPERTIES, PropertyInfoRestRep.class, "OVF");
} catch (Exception e) {
rep = null;
// now cannot access vip as well as cluster's coordinator
_log.error("Failed accessing last vip {}, {}", _lastVipSysClient.getServiceURI(), e);
}
}
PropertyInfoExt localProps = null;
// get controller properties cached locally
try {
localProps = getLocalRepository().getControllerOvfProperties();
} catch (LocalRepositoryException e) {
_log.error("Failed to retrive controller properties from local repository");
throw e;
}
// Try vip cached locally to get controller properties using internal api
if (rep == null) {
String vipURL = getUrl(localProps.getProperty("network_vip"), localProps.getProperty("network_vip6"));
SysClientFactory.SysClient sysClient = SysClientFactory.getSysClient(URI.create(vipURL));
try {
rep = sysClient.post(SysClientFactory.URI_GET_PROPERTIES, PropertyInfoRestRep.class, "OVF");
} catch (Exception e) {
_log.error("Failed accessing vip {}, {}", vipURL, e);
}
}
// get properties
if (rep == null) {
rep = getControllerPropsFromNode(localProps);
}
if (rep == null) {
_log.error("Failed to get controller properties from cluster");
throw SyssvcException.syssvcExceptions.failConnectControllerError("Cannot connect to controller via node addresses or vip");
}
// After getting properties from controller, check and compare if vip has changed.
// If vip change is found, update vip in local cache.
Map<String, String> diffProps = checkVipDiff(localProps, rep);
if (diffProps.size() > 0) {
try {
setLocalRepoControllerProps(diffProps);
_log.error("Successfully set vip in local repository");
} catch (LocalRepositoryException e) {
_log.error("Failed to set vip in local repository");
throw e;
}
} else {
_log.info("vip not changed");
}
// Cache the last known valid vip client, whether vip changed or not
// so that it can be used for the next poll interval
SysClientFactory.SysClient sysClient = SysClientFactory.getSysClient(URI.create(getUrl(rep.getProperty("network_vip"), rep.getProperty("network_vip6"))));
PropertyInfoRestRep propRep = null;
try {
propRep = sysClient.post(SysClientFactory.URI_GET_PROPERTIES, PropertyInfoRestRep.class, "OVF");
if (propRep != null) {
// cache the validated vip client where secret key is cached.
// so that if next poll cycle data node cannot connect to coordinator
// it can use this vip client to invoke internal api
_lastVipSysClient = sysClient;
}
} catch (Exception e) {
_log.error("Failed accessing vip {}, {}", _lastVipSysClient.getServiceURI(), e);
}
// also need check individual controller nodes to see if any address changed
// because in a cluster though some nodes address changed, data node may still
// can access to coordinator if majority nodes of a zookeeper ensemble remains
// If controller node address change detected, restart the node.
Map<String, String> nodeDiffProps = checkNodeAddressDiff(localProps, rep);
if (nodeDiffProps.size() > 0) {
try {
setLocalRepoControllerProps(nodeDiffProps);
_log.info("rebooting to get updated cluster addresses");
getLocalRepository().reboot();
} catch (Exception e) {
_log.error("Reboot failed, ", e);
throw e;
}
}
}
use of com.emc.storageos.coordinator.client.model.PropertyInfoExt in project coprhd-controller by CoprHD.
the class PropertyInfoTest method testDiff.
@Test
public void testDiff() {
Map<String, String> map = new HashMap<String, String>();
map.put("node_id", "node2");
map.put("system_connectemc_username", "username");
PropertyInfoExt propertyInfo = new PropertyInfoExt(map);
Map<String, String> newMap = new HashMap<String, String>();
newMap.put("node_id", "node4");
PropertyInfoExt propertyInfoNew = new PropertyInfoExt(newMap);
Assert.assertTrue(propertyInfo.diff(propertyInfoNew));
// non-existing property
propertyInfoNew.getAllProperties().put("dummy", "dummy");
Assert.assertTrue(propertyInfo.diff(propertyInfoNew));
// existing property
propertyInfoNew.getAllProperties().put("system_connectemc_username", "newname");
Assert.assertTrue(propertyInfo.diff(propertyInfoNew));
// empty value property
propertyInfoNew.getAllProperties().put("system_connectemc_username", "");
Assert.assertTrue(propertyInfo.diff(propertyInfoNew));
PropertyInfoExt prop1 = new PropertyInfoExt();
PropertyInfoExt prop2 = new PropertyInfoExt();
Assert.assertTrue(prop1.getDiffProperties(prop2).size() == 0);
prop2.addProperty("new1", "new1");
Assert.assertTrue(prop1.getDiffProperties(prop2).size() == 1);
Assert.assertTrue(prop2.getDiffProperties(prop1).get("new1").equals("new1"));
}
Aggregations