Search in sources :

Example 11 with Properties

use of org.ovirt.engine.api.model.Properties in project ovirt-engine by oVirt.

the class CustomPropertiesParser method fromMap.

/**
 * Create a Properties object from a map containing key:value pairs.
 *
 * @param properties
 *            The map containing key:value pairs.
 * @return A newly-created Properties object containing the key:value pairs.
 */
public static Properties fromMap(Map<String, String> properties) {
    Properties res = new Properties();
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        Property property = new Property();
        property.setName(entry.getKey());
        property.setValue(entry.getValue());
        res.getProperties().add(property);
    }
    return res;
}
Also used : Properties(org.ovirt.engine.api.model.Properties) Map(java.util.Map) HashMap(java.util.HashMap) Property(org.ovirt.engine.api.model.Property) CustomProperty(org.ovirt.engine.api.model.CustomProperty)

Example 12 with Properties

use of org.ovirt.engine.api.model.Properties in project ovirt-engine by oVirt.

the class OpenStackVolumeProviderMapper method map.

@Mapping(from = Provider.class, to = OpenStackVolumeProvider.class)
public static OpenStackVolumeProvider map(Provider<OpenStackVolumeProviderProperties> entity, OpenStackVolumeProvider template) {
    OpenStackVolumeProvider model = template != null ? template : new OpenStackVolumeProvider();
    if (entity.getId() != null) {
        model.setId(entity.getId().toString());
    }
    if (entity.getName() != null) {
        model.setName(entity.getName());
    }
    if (entity.getDescription() != null) {
        model.setDescription(entity.getDescription());
    }
    if (entity.getUrl() != null) {
        model.setUrl(entity.getUrl());
    }
    if (entity.getAuthUrl() != null) {
        model.setAuthenticationUrl(entity.getAuthUrl());
    }
    model.setRequiresAuthentication(entity.isRequiringAuthentication());
    if (entity.getUsername() != null) {
        model.setUsername(entity.getUsername());
    }
    // The password isn't mapped for security reasons.
    // if (entity.getPassword() != null) {
    // model.setPassword(entity.getPassword());
    // }
    Map<String, String> customProperties = entity.getCustomProperties();
    if (customProperties != null) {
        Properties properties = new Properties();
        for (Map.Entry<String, String> entry : customProperties.entrySet()) {
            Property property = new Property();
            property.setName(entry.getKey());
            property.setValue(entry.getValue());
            properties.getProperties().add(property);
        }
        model.setProperties(properties);
    }
    OpenStackVolumeProviderProperties additionalProperties = entity.getAdditionalProperties();
    if (additionalProperties != null) {
        if (additionalProperties.getTenantName() != null) {
            model.setTenantName(additionalProperties.getTenantName());
        }
        if (additionalProperties.getStoragePoolId() != null) {
            DataCenter dataCenter = new DataCenter();
            dataCenter.setId(additionalProperties.getStoragePoolId().toString());
            model.setDataCenter(dataCenter);
        }
    }
    return model;
}
Also used : DataCenter(org.ovirt.engine.api.model.DataCenter) OpenStackVolumeProviderProperties(org.ovirt.engine.core.common.businessentities.storage.OpenStackVolumeProviderProperties) OpenStackVolumeProvider(org.ovirt.engine.api.model.OpenStackVolumeProvider) Properties(org.ovirt.engine.api.model.Properties) OpenStackVolumeProviderProperties(org.ovirt.engine.core.common.businessentities.storage.OpenStackVolumeProviderProperties) Map(java.util.Map) HashMap(java.util.HashMap) Property(org.ovirt.engine.api.model.Property) Mapping(org.ovirt.engine.api.restapi.types.Mapping)

Example 13 with Properties

use of org.ovirt.engine.api.model.Properties in project ovirt-engine by oVirt.

the class V3ClusterOutAdapter method adapt.

@Override
public V3Cluster adapt(Cluster from) {
    V3Cluster to = new V3Cluster();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptOut(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetBallooningEnabled()) {
        to.setBallooningEnabled(from.isBallooningEnabled());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptOut(from.getCpu()));
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptOut(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptOut(from.getDisplay()));
    }
    if (from.isSetErrorHandling()) {
        to.setErrorHandling(adaptOut(from.getErrorHandling()));
    }
    if (from.isSetFencingPolicy()) {
        to.setFencingPolicy(adaptOut(from.getFencingPolicy()));
    }
    if (from.isSetGlusterService()) {
        to.setGlusterService(from.isGlusterService());
    }
    if (from.isSetHaReservation()) {
        to.setHaReservation(from.isHaReservation());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetKsm()) {
        to.setKsm(adaptOut(from.getKsm()));
    }
    if (from.isSetMaintenanceReasonRequired()) {
        to.setMaintenanceReasonRequired(from.isMaintenanceReasonRequired());
    }
    if (from.isSetManagementNetwork()) {
        to.setManagementNetwork(adaptOut(from.getManagementNetwork()));
    }
    if (from.isSetMemoryPolicy()) {
        to.setMemoryPolicy(adaptOut(from.getMemoryPolicy()));
    }
    if (from.isSetMigration()) {
        to.setMigration(adaptOut(from.getMigration()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetOptionalReason()) {
        to.setOptionalReason(from.isOptionalReason());
    }
    if (from.isSetRequiredRngSources()) {
        to.setRequiredRngSources(new V3RngSources());
        to.getRequiredRngSources().getRngSources().addAll(adaptRngSources(from));
    }
    if (from.isSetSerialNumber()) {
        to.setSerialNumber(adaptOut(from.getSerialNumber()));
    }
    if (from.isSetSupportedVersions()) {
        to.setSupportedVersions(new V3SupportedVersions());
        to.getSupportedVersions().getVersions().addAll(adaptOut(from.getSupportedVersions().getVersions()));
    }
    if (from.isSetThreadsAsCores()) {
        to.setThreadsAsCores(from.isThreadsAsCores());
    }
    if (from.isSetTrustedService()) {
        to.setTrustedService(from.isTrustedService());
    }
    if (from.isSetTunnelMigration()) {
        to.setTunnelMigration(from.isTunnelMigration());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptOut(from.getVersion()));
    }
    if (from.isSetVirtService()) {
        to.setVirtService(from.isVirtService());
    }
    // In V3 the scheduling policy was part of the cluster, so we need to retrieve the details and populate the
    // "policy" and "thresholds" elements:
    SchedulingPolicy fromPolicy = from.getSchedulingPolicy();
    if (fromPolicy != null && fromPolicy.isSetId()) {
        SystemResource systemResource = BackendApiResource.getInstance();
        SchedulingPoliciesResource policiesResource = systemResource.getSchedulingPoliciesResource();
        SchedulingPolicyResource policyResource = policiesResource.getPolicyResource(fromPolicy.getId());
        try {
            fromPolicy = policyResource.get();
        } catch (WebApplicationException exception) {
        // If an application exception is generated while retrieving the details of the scheduling policy it
        // is safe to ignore it, as it may be that the user just doesn't have permission to see the policy, but
        // she may still have permissions to see the other details of the cluster.
        }
        V3SchedulingPolicy toPolicy = to.getSchedulingPolicy();
        if (toPolicy == null) {
            toPolicy = new V3SchedulingPolicy();
            to.setSchedulingPolicy(toPolicy);
        }
        if (fromPolicy.isSetId()) {
            toPolicy.setId(fromPolicy.getId());
        }
        if (fromPolicy.isSetHref()) {
            toPolicy.setHref(fromPolicy.getHref());
        }
        if (fromPolicy.isSetName() && !toPolicy.isSetPolicy()) {
            toPolicy.setPolicy(fromPolicy.getName());
        }
        Properties fromProperties = fromPolicy.getProperties();
        if (fromProperties != null) {
            Integer fromDuration = getIntegerProperty(fromProperties, "CpuOverCommitDurationMinutes");
            if (fromDuration != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setDuration(fromDuration);
            }
            Integer fromHigh = getIntegerProperty(fromProperties, "HighUtilization");
            if (fromHigh != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setHigh(fromHigh);
            }
            Integer fromLow = getIntegerProperty(fromProperties, "LowUtilization");
            if (fromLow != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setLow(fromLow);
            }
        }
    }
    return to;
}
Also used : V3Cluster(org.ovirt.engine.api.v3.types.V3Cluster) V3SchedulingPolicyThresholds(org.ovirt.engine.api.v3.types.V3SchedulingPolicyThresholds) V3RngSources(org.ovirt.engine.api.v3.types.V3RngSources) SchedulingPoliciesResource(org.ovirt.engine.api.resource.SchedulingPoliciesResource) WebApplicationException(javax.ws.rs.WebApplicationException) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy) SchedulingPolicyResource(org.ovirt.engine.api.resource.SchedulingPolicyResource) V3SupportedVersions(org.ovirt.engine.api.v3.types.V3SupportedVersions) SystemResource(org.ovirt.engine.api.resource.SystemResource) SchedulingPolicy(org.ovirt.engine.api.model.SchedulingPolicy) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy) Properties(org.ovirt.engine.api.model.Properties)

Example 14 with Properties

use of org.ovirt.engine.api.model.Properties in project ovirt-engine by oVirt.

the class V3ExternalProviderInAdapter method adapt.

@Override
public ExternalProvider adapt(V3ExternalProvider from) {
    ExternalProvider to = new ExternalProvider();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetAuthenticationUrl()) {
        to.setAuthenticationUrl(from.getAuthenticationUrl());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetPassword()) {
        to.setPassword(from.getPassword());
    }
    if (from.isSetProperties()) {
        to.setProperties(new Properties());
        to.getProperties().getProperties().addAll(adaptIn(from.getProperties().getProperties()));
    }
    if (from.isSetRequiresAuthentication()) {
        to.setRequiresAuthentication(from.isRequiresAuthentication());
    }
    if (from.isSetUrl()) {
        to.setUrl(from.getUrl());
    }
    if (from.isSetUsername()) {
        to.setUsername(from.getUsername());
    }
    return to;
}
Also used : ExternalProvider(org.ovirt.engine.api.model.ExternalProvider) V3ExternalProvider(org.ovirt.engine.api.v3.types.V3ExternalProvider) Properties(org.ovirt.engine.api.model.Properties)

Example 15 with Properties

use of org.ovirt.engine.api.model.Properties in project ovirt-engine by oVirt.

the class V3ClusterHelper method arePoliciesCompatible.

/**
 * Checks if the given V3 and V4 scheduling policies are compatible.
 *
 * @return {@code true} iif the two policies are compatible
 */
private static boolean arePoliciesCompatible(V3SchedulingPolicy v3Policy, SchedulingPolicy v4Policy) {
    // The V3 "policy" attribute must be equal to the V4 "name" attribute:
    String v3Name = v3Policy.getName();
    if (v3Name == null) {
        v3Name = v3Policy.getPolicy();
    }
    if (v3Name != null && !Objects.equals(v3Name, v4Policy.getName())) {
        return false;
    }
    // All the V3 threshold must match the equivalent V4 properties:
    V3SchedulingPolicyThresholds v3Thresholds = v3Policy.getThresholds();
    Properties v4Properties = v4Policy.getProperties();
    if (v3Thresholds != null) {
        Integer v3Duration = v3Thresholds.getDuration();
        Integer v4Duration = getIntegerProperty(v4Properties, "CpuOverCommitDurationMinutes");
        if (!arePropertiesCompatible(v3Duration, v4Duration)) {
            return false;
        }
        Integer v3High = v3Thresholds.getHigh();
        Integer v4High = getIntegerProperty(v4Properties, "HighUtilization");
        if (!arePropertiesCompatible(v3High, v4High)) {
            return false;
        }
        Integer v3Low = v3Thresholds.getLow();
        Integer v4Low = getIntegerProperty(v4Properties, "LowUtilization");
        if (!arePropertiesCompatible(v3Low, v4Low)) {
            return false;
        }
    }
    // All the tests passed, so the policies are compatible:
    return true;
}
Also used : V3SchedulingPolicyThresholds(org.ovirt.engine.api.v3.types.V3SchedulingPolicyThresholds) Properties(org.ovirt.engine.api.model.Properties)

Aggregations

Properties (org.ovirt.engine.api.model.Properties)18 Map (java.util.Map)5 Property (org.ovirt.engine.api.model.Property)5 HashMap (java.util.HashMap)4 Mapping (org.ovirt.engine.api.restapi.types.Mapping)3 OpenStackImageProvider (org.ovirt.engine.api.model.OpenStackImageProvider)2 OpenStackNetworkProvider (org.ovirt.engine.api.model.OpenStackNetworkProvider)2 OpenStackVolumeProvider (org.ovirt.engine.api.model.OpenStackVolumeProvider)2 SchedulingPolicy (org.ovirt.engine.api.model.SchedulingPolicy)2 V3SchedulingPolicy (org.ovirt.engine.api.v3.types.V3SchedulingPolicy)2 V3SchedulingPolicyThresholds (org.ovirt.engine.api.v3.types.V3SchedulingPolicyThresholds)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 CustomProperty (org.ovirt.engine.api.model.CustomProperty)1 DataCenter (org.ovirt.engine.api.model.DataCenter)1 ExternalHostProvider (org.ovirt.engine.api.model.ExternalHostProvider)1 ExternalProvider (org.ovirt.engine.api.model.ExternalProvider)1 HostNic (org.ovirt.engine.api.model.HostNic)1 IpAddressAssignments (org.ovirt.engine.api.model.IpAddressAssignments)1 LinkLayerDiscoveryProtocolElement (org.ovirt.engine.api.model.LinkLayerDiscoveryProtocolElement)1 NetworkAttachment (org.ovirt.engine.api.model.NetworkAttachment)1