Search in sources :

Example 6 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep in project coprhd-controller by CoprHD.

the class ClusterAddressPoller method getControllerPropsFromNode.

/**
 * Get controller properties using internal api from controller nodes.
 * This method is invoked when vip is changed
 *
 * @param localProps config properties cached locally on data node
 * @return
 */
private PropertyInfoRestRep getControllerPropsFromNode(PropertyInfoExt localProps) {
    int nodeCount = Integer.parseInt(localProps.getProperty("node_count"));
    PropertyInfoRestRep rep = null;
    for (int i = 1; i <= nodeCount; i++) {
        String baseNodeUrl = getUrl(localProps.getProperty(String.format(ADDRESSV4_FORMAT, i)), localProps.getProperty(String.format(ADDRESSV6_FORMAT, i)));
        SysClientFactory.SysClient sysClient = SysClientFactory.getSysClient(URI.create(baseNodeUrl));
        try {
            rep = sysClient.post(SysClientFactory.URI_GET_PROPERTIES, PropertyInfoRestRep.class, "OVF");
            break;
        } catch (Exception e) {
            // now cannot access vip as well as cluster's coordinator
            _log.error("Failed accessing url {}, {}", baseNodeUrl, e);
            rep = null;
            continue;
        }
    }
    return rep;
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) SysClientFactory(com.emc.storageos.systemservices.impl.client.SysClientFactory) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException)

Example 7 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep in project coprhd-controller by CoprHD.

the class LocalUserMode method setupLocalUserModeBaseClass.

@BeforeClass
public static synchronized void setupLocalUserModeBaseClass() throws Exception {
    // get the Bourne IP from parameter
    String param_IP = System.getProperty("APP_HOST_NAMES");
    if (param_IP != null) {
        controllerNodeEndpoint = param_IP;
    } else {
        Properties properties = new Properties();
        properties.load(ClassLoader.class.getResourceAsStream("/test-env.conf"));
        controllerNodeEndpoint = properties.getProperty("APP_HOST_NAMES");
    }
    logger.info("Controller node endpoint: " + controllerNodeEndpoint);
    systemClient = new ViPRSystemClient(controllerNodeEndpoint, true).withLogin("root", rootPassword);
    coreClient = new ViPRCoreClient(controllerNodeEndpoint, true).withLogin("root", rootPassword);
    waitForClusterStable();
    PropertyInfoRestRep propertyInfoRestRep = systemClient.config().getProperties();
    String viprDataIps = propertyInfoRestRep.getProperty("system_datanode_ipaddrs");
    if (viprDataIps != null) {
        dataNodeEndpoint = viprDataIps.split(",")[0];
    }
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) ViPRSystemClient(com.emc.vipr.client.ViPRSystemClient) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass)

Example 8 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep 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;
        }
    }
}
Also used : LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) SysClientFactory(com.emc.storageos.systemservices.impl.client.SysClientFactory) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException)

Example 9 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep in project coprhd-controller by CoprHD.

the class LocalPasswordHandler method getPassword.

private String getPassword(String username) throws CoordinatorClientException, LocalRepositoryException {
    PropertyInfoRestRep props = null;
    try {
        props = _cfg.getProperties(PropCategory.CONFIG.toString());
    } catch (Exception e) {
        throw APIException.internalServerErrors.getObjectFromError("password", "coordinator", e);
    }
    String propertyKey = String.format(SYSTEM_ENCPASSWORD_FORMAT, username);
    String oldPassword = props.getProperty(propertyKey);
    if (oldPassword == null) {
        _log.error("password not found for " + username);
        return "";
    }
    return oldPassword;
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException)

Example 10 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep in project coprhd-controller by CoprHD.

the class ConfigService method updatePropertiesCommon.

/**
 * Common method called by setProps and resetProps
 * Callers should prepare valid updateProps and deleteProps,
 * by verifying against validateAndUpdateProperties
 * before call this method
 *
 * @param updateProps update properties' keys and values
 * @param deleteKeys delete properties' keys
 * @throws Exception
 * @throws CoordinatorClientException
 */
private Response updatePropertiesCommon(PropertyInfoRestRep updateProps, List<String> deleteKeys) throws Exception {
    // validate
    if (!_coordinator.isClusterUpgradable()) {
        throw APIException.serviceUnavailable.clusterStateNotStable();
    }
    StringBuilder propChanges = new StringBuilder();
    // get current property set
    PropertyInfoRestRep oldProps = new PropertyInfoRestRep();
    oldProps.addProperties(getTargetPropsCommon().getAllProperties());
    boolean doSetTarget = false;
    PropertyInfoRestRep currentProps = _coordinator.getTargetProperties();
    // remove properties
    if (deleteKeys != null && !deleteKeys.isEmpty()) {
        doSetTarget = true;
        for (String key : deleteKeys) {
            currentProps.removeProperty(key);
            propChanges.append(key);
            propChanges.append(" deleted");
        }
        currentProps.removeProperties(deleteKeys);
    }
    // update properties, increment config_version
    if (updateProps != null && !updateProps.isEmpty()) {
        doSetTarget = true;
        currentProps.addProperties(updateProps.getAllProperties());
        String configVersion = System.currentTimeMillis() + "";
        currentProps.addProperty(PropertyInfoRestRep.CONFIG_VERSION, configVersion);
        if (propChanges.length() > 0) {
            propChanges.append(",");
        }
        propChanges.append(PropertyInfoRestRep.CONFIG_VERSION);
        propChanges.append("=");
        propChanges.append(configVersion);
    }
    if (doSetTarget) {
        // perform before handlers
        _propertyHandlers.before(oldProps, currentProps);
        _coordinator.setTargetProperties(currentProps.getAllProperties());
        for (Map.Entry<String, String> entry : updateProps.getAllProperties().entrySet()) {
            if (propChanges.length() > 0) {
                propChanges.append(",");
            }
            propChanges.append(entry.getKey());
            propChanges.append("=");
            // Hide encrypted string in audit log
            if (PropertyInfoExt.isEncryptedProperty(entry.getKey())) {
                propChanges.append(HIDDEN_TEXT_MASK);
            } else {
                propChanges.append(entry.getValue());
            }
        }
        auditConfig(OperationTypeEnum.UPDATE_SYSTEM_PROPERTY, AuditLogManager.AUDITLOG_SUCCESS, null, propChanges.toString());
        // perform after handlers
        _propertyHandlers.after(oldProps, currentProps);
    }
    ClusterInfo clusterInfo = _coordinator.getClusterInfo();
    if (clusterInfo == null) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster information");
    }
    return toClusterResponse(clusterInfo);
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

PropertyInfoRestRep (com.emc.storageos.model.property.PropertyInfoRestRep)19 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 TreeMap (java.util.TreeMap)4 PropertyInfoUpdate (com.emc.storageos.model.property.PropertyInfoUpdate)3 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)3 PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)2 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)2 SyssvcException (com.emc.storageos.systemservices.exceptions.SyssvcException)2 SysClientFactory (com.emc.storageos.systemservices.impl.client.SysClientFactory)2 ViPRSystemClient (com.emc.vipr.client.ViPRSystemClient)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ConfigVersion (com.emc.storageos.coordinator.client.model.ConfigVersion)1 PowerOffState (com.emc.storageos.coordinator.client.model.PowerOffState)1 SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)1 StorageDriversInfo (com.emc.storageos.coordinator.client.model.StorageDriversInfo)1 VdcConfigVersion (com.emc.storageos.coordinator.client.model.VdcConfigVersion)1