Search in sources :

Example 11 with PropertyInfoRestRep

use of com.emc.storageos.model.property.PropertyInfoRestRep 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());
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException)

Example 12 with PropertyInfoRestRep

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

the class ConfigService method getProperties.

/**
 * Get system configuration properties
 *
 * @brief Get system properties
 * @prereq none
 * @param category - type of properties to return: all, config, ovf, mutated, secrets (require SecurityAdmin role)
 *            or obsolete
 * @return Properties Information if success. Error response, if error./**
 */
@GET
@Path("properties/")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public PropertyInfoRestRep getProperties(@DefaultValue("all") @QueryParam("category") String category) throws Exception {
    switch(PropCategory.valueOf(category.toUpperCase())) {
        case ALL:
            return getTargetPropsCommon();
        case CONFIG:
            return new PropertyInfoRestRep(getConfigProperties());
        case OVF:
            return new PropertyInfoRestRep(getPropertiesOvf());
        case REDEPLOY:
            Map<String, String> props = getPropertiesOvf();
            props.remove(MODE);
            props.remove(NODE_ID);
            Map<String, String> clusterInfo = new HashMap();
            Set<Map.Entry<String, String>> ovfProps = props.entrySet();
            for (Map.Entry<String, String> ovfProp : ovfProps) {
                String parameter = propertyToParameters.get(ovfProp.getKey());
                if (parameter == null) {
                    continue;
                }
                clusterInfo.put(parameter, ovfProp.getValue());
            }
            // Add ipsec key
            clusterInfo.put(IPSEC_KEY, ipsecConfig.getPreSharedKey());
            // Add version info
            RepositoryInfo info = _coordinator.getTargetInfo(RepositoryInfo.class);
            clusterInfo.put(VERSION, info.getCurrentVersion().toString());
            _log.info("clusterInfo={}", clusterInfo);
            return new PropertyInfoRestRep(clusterInfo);
        case MUTATED:
            return new PropertyInfoRestRep(getMutatedProps());
        case SECRETS:
            StorageOSUser user = getUserFromContext();
            if (!user.getRoles().contains(Role.SECURITY_ADMIN.toString())) {
                throw APIException.forbidden.onlySecurityAdminsCanGetSecrets();
            }
            return getTargetPropsCommon(false);
        case OBSOLETE:
            return new PropertyInfoRestRep(getObsoleteProperties());
        default:
            throw APIException.badRequests.invalidParameter("category", category);
    }
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) HashMap(java.util.HashMap) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with PropertyInfoRestRep

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

the class ConfigService method setProperties.

/**
 * Update system configuration properties
 *
 * @brief Update system properties
 * @param setProperty Property's key value pair.
 * @prereq Cluster state should be STABLE
 * @return Cluster information
 */
@PUT
@Path("properties/")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response setProperties(PropertyInfoUpdate setProperty) throws Exception {
    PropertyInfoRestRep targetPropInfo = getTargetPropsCommon();
    _log.info("setProperties(): {}", setProperty);
    PropertyInfoRestRep updateProps = getUpdateProps(setProperty, targetPropInfo.getAllProperties());
    return updatePropertiesCommon(updateProps, null);
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with PropertyInfoRestRep

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

the class ConfigService method resetProps.

/**
 * Reset configuration properties to their default values. Properties with
 * no default values will remain unchanged
 *
 * @brief Reset system properties
 * @param propertyList property list
 * @prereq Cluster state should be STABLE
 * @return Cluster information
 */
@POST
@Path("properties/reset/")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response resetProps(PropertyList propertyList, @QueryParam("removeObsolete") String forceRemove) throws Exception {
    // get metadata
    Map<String, PropertyMetadata> metadata = PropertiesMetadata.getGlobalMetadata();
    // get target property set
    PropertyInfoRestRep targetPropInfo = getTargetPropsCommon();
    // get reset property set
    PropertyInfoRestRep resetProps = getResetProps(propertyList, targetPropInfo.getAllProperties(), metadata);
    // get obsolete property set
    List<String> obsoleteProps = isSet(forceRemove) ? getObsoleteProps(targetPropInfo.getAllProperties(), metadata) : null;
    // update properties with default value
    return updatePropertiesCommon(resetProps, obsoleteProps);
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) PropertyMetadata(com.emc.storageos.model.property.PropertyMetadata) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 15 with PropertyInfoRestRep

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

the class ConfigService method getUpdateProps.

/**
 * Get update property set, which values are different from target
 *
 * @param propsToUpdate property set to update in request
 * @param targetProps target properties
 * @return update property set
 */
private PropertyInfoRestRep getUpdateProps(final PropertyInfoUpdate propsToUpdate, final Map<String, String> targetProps) {
    // validate the changed property against it's metadata to ensure property
    // integrity.
    validateAndUpdateProperties(propsToUpdate.getAllProperties(), false);
    PropertyInfoRestRep updateProps = new PropertyInfoRestRep();
    for (Map.Entry<String, String> entry : propsToUpdate.getAllProperties().entrySet()) {
        final String key = entry.getKey();
        final String value = entry.getValue();
        if (targetProps.containsKey(key) && !targetProps.get(key).equals(value)) {
            updateProps.addProperty(key, value);
        } else if (!targetProps.containsKey(key)) {
            updateProps.addProperty(key, value);
        }
    }
    return updateProps;
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) 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