use of org.ovirt.engine.api.model.SchedulingPolicy in project ovirt-engine by oVirt.
the class V3ClusterHelper method assignCompatiblePolicy.
/**
* Makes sure that the V4 cluster has a reference to a scheduling policy that is compatible with the one specified
* by the given V3 cluster. If that isn't possible throws an exception that will result in an HTTP error response
* sent to the caller.
*/
public static void assignCompatiblePolicy(V3Cluster v3Cluster, Cluster v4Cluster) {
V3SchedulingPolicy v3Policy = v3Cluster.getSchedulingPolicy();
SchedulingPolicy v4Policy = v4Cluster.getSchedulingPolicy();
boolean v3IsSet = v3Policy != null && (v3Policy.isSetName() || v3Policy.isSetPolicy());
boolean v4IsSet = v4Policy != null && (v4Policy.isSetName() || v4Policy.isSetId());
if (v3IsSet && !v4IsSet) {
SchedulingPolicy v4CompatiblePolicy = findCompatiblePolicy(v3Policy);
if (v4CompatiblePolicy != null) {
v4Policy = new SchedulingPolicy();
v4Policy.setId(v4CompatiblePolicy.getId());
v4Cluster.setSchedulingPolicy(v4Policy);
} else {
V3Fault fault = new V3Fault();
fault.setReason("Operation Failed");
fault.setDetail("Can't find a compatible scheduling policy.");
Response response = Response.serverError().entity(fault).build();
throw new WebApplicationException(response);
}
}
}
use of org.ovirt.engine.api.model.SchedulingPolicy in project ovirt-engine by oVirt.
the class SchedulingPolicyMapper method map.
@Mapping(from = ClusterPolicy.class, to = SchedulingPolicy.class)
public static SchedulingPolicy map(ClusterPolicy entity, SchedulingPolicy template) {
SchedulingPolicy model = template != null ? template : new SchedulingPolicy();
model.setId(entity.getId().toString());
model.setName(entity.getName());
model.setDescription(entity.getDescription());
model.setLocked(entity.isLocked());
model.setDefaultPolicy(entity.isDefaultPolicy());
if (entity.getParameterMap() != null && !entity.getParameterMap().isEmpty()) {
model.setProperties(CustomPropertiesParser.fromMap(entity.getParameterMap()));
}
return model;
}
use of org.ovirt.engine.api.model.SchedulingPolicy in project ovirt-engine by oVirt.
the class V3SchedulingPolicyInAdapter method adapt.
@Override
public SchedulingPolicy adapt(V3SchedulingPolicy from) {
SchedulingPolicy to = new SchedulingPolicy();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptIn(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptIn(from.getActions()));
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetDefaultPolicy()) {
to.setDefaultPolicy(from.isDefaultPolicy());
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.isSetLocked()) {
to.setLocked(from.isLocked());
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetProperties()) {
to.setProperties(new Properties());
to.getProperties().getProperties().addAll(adaptIn(from.getProperties().getProperties()));
}
return to;
}
use of org.ovirt.engine.api.model.SchedulingPolicy in project ovirt-engine by oVirt.
the class ClusterMapper method map.
@Mapping(from = org.ovirt.engine.api.model.Cluster.class, to = Cluster.class)
public static Cluster map(org.ovirt.engine.api.model.Cluster model, Cluster template) {
Cluster entity = template != null ? template : new Cluster();
if (model.isSetSwitchType()) {
entity.setRequiredSwitchTypeForCluster(SwitchTypeMapper.mapFromModel(model.getSwitchType()));
}
if (model.isSetFirewallType()) {
entity.setFirewallType(FirewallTypeMapper.mapFromModel(model.getFirewallType()));
}
if (model.isSetId()) {
entity.setId(GuidUtils.asGuid(model.getId()));
}
if (model.isSetName()) {
entity.setName(model.getName());
}
if (model.isSetDescription()) {
entity.setDescription(model.getDescription());
}
if (model.isSetComment()) {
entity.setComment(model.getComment());
}
if (model.isSetCpu() && model.getCpu().isSetType()) {
entity.setCpuName(model.getCpu().getType());
}
if (model.isSetCpu() && model.getCpu().isSetArchitecture()) {
entity.setArchitecture(CPUMapper.map(model.getCpu().getArchitecture(), null));
}
if (model.isSetDataCenter() && model.getDataCenter().isSetId()) {
entity.setStoragePoolId(GuidUtils.asGuid(model.getDataCenter().getId()));
}
if (model.isSetVersion() && model.getVersion().getMajor() != null && model.getVersion().getMinor() != null) {
entity.setCompatibilityVersion(VersionMapper.map(model.getVersion()));
}
if (model.isSetMemoryPolicy()) {
entity = map(model.getMemoryPolicy(), entity);
} else if (model.isSetVersion() && model.getVersion().getMajor() != null && model.getVersion().getMinor() != null && greaterOrEqual(model.getVersion(), min_thp_version)) {
entity.setTransparentHugepages(true);
}
SchedulingPolicy schedulingPolicy = model.getSchedulingPolicy();
if (schedulingPolicy != null) {
if (schedulingPolicy.isSetName()) {
entity.setClusterPolicyName(schedulingPolicy.getName());
}
if (schedulingPolicy.isSetId()) {
entity.setClusterPolicyId(GuidUtils.asGuid(schedulingPolicy.getId()));
}
}
if (model.isSetErrorHandling() && model.getErrorHandling().isSetOnError()) {
entity.setMigrateOnError(map(model.getErrorHandling().getOnError(), null));
}
if (model.isSetVirtService()) {
entity.setVirtService(model.isVirtService());
}
if (model.isSetGlusterService()) {
entity.setGlusterService(model.isGlusterService());
}
if (model.isSetThreadsAsCores()) {
entity.setCountThreadsAsCores(model.isThreadsAsCores());
}
if (model.isSetTunnelMigration()) {
entity.setTunnelMigration(model.isTunnelMigration());
}
if (model.isSetTrustedService()) {
entity.setTrustedService(model.isTrustedService());
}
if (model.isSetHaReservation()) {
entity.setHaReservation(model.isHaReservation());
}
if (model.isSetOptionalReason()) {
entity.setOptionalReasonRequired(model.isOptionalReason());
}
if (model.isSetMaintenanceReasonRequired()) {
entity.setMaintenanceReasonRequired(model.isMaintenanceReasonRequired());
}
if (model.isSetBallooningEnabled()) {
entity.setEnableBallooning(model.isBallooningEnabled());
}
if (model.isSetKsm()) {
if (model.getKsm().isSetEnabled()) {
entity.setEnableKsm(model.getKsm().isEnabled());
}
if (model.getKsm().isSetMergeAcrossNodes()) {
entity.setKsmMergeAcrossNumaNodes(model.getKsm().isMergeAcrossNodes());
}
}
if (model.isSetDisplay() && model.getDisplay().isSetProxy()) {
entity.setSpiceProxy("".equals(model.getDisplay().getProxy()) ? null : model.getDisplay().getProxy());
}
if (model.isSetSerialNumber()) {
SerialNumberMapper.copySerialNumber(model.getSerialNumber(), entity);
}
/*
* For backward compatibility additional rng sources are presented in <required_rng_sources> together with
* implicit /dev/urandom or /dev/random source. <required_rng_sources> should be changed to
* <additional_rng_sources> during next api change.
*/
if (model.isSetRequiredRngSources()) {
entity.getAdditionalRngSources().clear();
entity.getAdditionalRngSources().addAll(RngDeviceMapper.mapRngSources(model.getRequiredRngSources().getRequiredRngSources()));
entity.getAdditionalRngSources().remove(VmRngDevice.Source.RANDOM);
entity.getAdditionalRngSources().remove(VmRngDevice.Source.URANDOM);
}
if (model.isSetFencingPolicy()) {
entity.setFencingPolicy(FencingPolicyMapper.map(model.getFencingPolicy(), null));
}
if (model.isSetMigration()) {
ClusterMigrationOptionsMapper.copyMigrationOptions(model.getMigration(), entity);
}
if (model.isSetMacPool() && model.getMacPool().isSetId()) {
entity.setMacPoolId(GuidUtils.asGuid(model.getMacPool().getId()));
}
// properties will override thresholds
if (model.isSetCustomSchedulingPolicyProperties()) {
Map<String, String> properties = entity.getClusterPolicyProperties();
if (properties == null) {
properties = new HashMap<>();
entity.setClusterPolicyProperties(properties);
}
Map<String, String> customProperties = CustomPropertiesParser.toMap(model.getCustomSchedulingPolicyProperties());
properties.putAll(customProperties);
}
if (model.isSetGlusterTunedProfile()) {
entity.setGlusterTunedProfile(model.getGlusterTunedProfile());
}
if (model.isSetExternalNetworkProviders()) {
List<ExternalProvider> externalNetworkProviders = model.getExternalNetworkProviders().getExternalProviders();
if (externalNetworkProviders.size() == 0) {
entity.setDefaultNetworkProviderId(null);
} else {
// Ignore everything but the first external provider, because engine's Cluster currently supports
// only a single external network provider
String providerId = externalNetworkProviders.get(0).getId();
entity.setDefaultNetworkProviderId(providerId == null ? null : GuidUtils.asGuid(providerId));
}
}
return entity;
}
use of org.ovirt.engine.api.model.SchedulingPolicy 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;
}
Aggregations