Search in sources :

Example 1 with LocalRepositoryException

use of com.emc.storageos.systemservices.exceptions.LocalRepositoryException in project coprhd-controller by CoprHD.

the class LocalPasswordHandler method updateUserPasswordProperty.

/**
 * when updating localuser's encpassword property, this method should be call instead of
 * updateProperty method.
 *
 * it will update encpassword property, it also update user's expiry_date property and
 * user's password history.
 *
 * expiry_date system properties is for generate /etc/shadow file to block ssh login after
 * user's password expired.
 *
 * @param username
 * @param value
 * @throws CoordinatorClientException
 * @throws LocalRepositoryException
 */
private void updateUserPasswordProperty(String username, String value, boolean bReset) throws CoordinatorClientException, LocalRepositoryException {
    String encpasswordProperty = String.format(SYSTEM_ENCPASSWORD_FORMAT, username);
    PropertyInfoUpdate props = new PropertyInfoUpdate();
    props.addProperty(encpasswordProperty, value);
    Calendar newExpireTime = getExpireTimeFromNow();
    if (username.equals("root") || username.equals("svcuser")) {
        // add expiry_date system property
        String configExpireDays = getPasswordUtils().getConfigProperty(Constants.PASSWORD_EXPIRE_DAYS);
        int intConfigExpireDays = NumberUtils.toInt(configExpireDays);
        int daysAfterEpoch = 0;
        if (intConfigExpireDays != 0) {
            daysAfterEpoch = PasswordUtils.getDaysAfterEpoch(newExpireTime);
        }
        String expirydaysProperty = String.format(Constants.SYSTEM_PASSWORD_EXPIRY_FORMAT, username);
        _log.info("updating " + expirydaysProperty + " to " + daysAfterEpoch);
        props.addProperty(expirydaysProperty, String.valueOf(daysAfterEpoch));
    }
    try {
        _cfg.setProperties(props);
        if (username.equals("proxyuser")) {
            value = _passwordUtils.getEncryptedString(value);
        }
        _passwordUtils.updatePasswordHistory(username, value, newExpireTime, bReset);
    } catch (Exception e) {
        throw APIException.internalServerErrors.updateObjectError("properties", e);
    }
}
Also used : Calendar(java.util.Calendar) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) PropertyInfoUpdate(com.emc.storageos.model.property.PropertyInfoUpdate)

Example 2 with LocalRepositoryException

use of com.emc.storageos.systemservices.exceptions.LocalRepositoryException in project coprhd-controller by CoprHD.

the class LocalPasswordHandler method updateProperty.

public void updateProperty(String key, String value) throws CoordinatorClientException, LocalRepositoryException {
    PropertyInfoUpdate props = new PropertyInfoUpdate();
    props.addProperty(key, value);
    _log.info("Calling ConfigService to update property: ", key);
    try {
        _cfg.setProperties(props);
    } catch (Exception e) {
        throw APIException.internalServerErrors.updateObjectError("properties", e);
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) PropertyInfoUpdate(com.emc.storageos.model.property.PropertyInfoUpdate)

Example 3 with LocalRepositoryException

use of com.emc.storageos.systemservices.exceptions.LocalRepositoryException 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 4 with LocalRepositoryException

use of com.emc.storageos.systemservices.exceptions.LocalRepositoryException 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 5 with LocalRepositoryException

use of com.emc.storageos.systemservices.exceptions.LocalRepositoryException in project coprhd-controller by CoprHD.

the class UpgradeService method getImage.

/**
 * *Internal API, used only between nodes*
 * <p>
 * Get image
 *
 * @param versionStr Version to be retrieved
 * @return Image details
 */
@GET
@Path("internal/image/")
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getImage(@QueryParam("version") String versionStr) {
    _log.info("getImage({})", versionStr);
    final SoftwareVersion version;
    try {
        version = new SoftwareVersion(versionStr);
    } catch (InvalidSoftwareVersionException e) {
        throw APIException.badRequests.parameterIsNotValid("version");
    }
    final InputStream in;
    try {
        in = LocalRepository.getInstance().getImageInputStream(version);
    } catch (LocalRepositoryException e) {
        throw APIException.internalServerErrors.getObjectFromError("image input stream", "local repository", e);
    }
    return Response.ok(in).type(MediaType.APPLICATION_OCTET_STREAM).build();
}
Also used : InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) InputStream(java.io.InputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)5 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)3 PropertyInfoRestRep (com.emc.storageos.model.property.PropertyInfoRestRep)2 PropertyInfoUpdate (com.emc.storageos.model.property.PropertyInfoUpdate)2 PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)1 SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)1 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)1 SyssvcException (com.emc.storageos.systemservices.exceptions.SyssvcException)1 SysClientFactory (com.emc.storageos.systemservices.impl.client.SysClientFactory)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1