Search in sources :

Example 1 with Property

use of build.bazel.remote.execution.v2.Platform.Property in project bazel-buildfarm by bazelbuild.

the class ShardWorkerContext method getMatchProvisions.

static SetMultimap<String, String> getMatchProvisions(Platform platform, Iterable<ExecutionPolicy> policies, int executeStageWidth) {
    ImmutableSetMultimap.Builder<String, String> provisions = ImmutableSetMultimap.builder();
    Platform matchPlatform = ExecutionPolicies.getMatchPlatform(platform, policies);
    for (Platform.Property property : matchPlatform.getPropertiesList()) {
        provisions.put(property.getName(), property.getValue());
    }
    provisions.put(PROVISION_CORES_NAME, String.format("%d", executeStageWidth));
    return provisions.build();
}
Also used : Platform(build.bazel.remote.execution.v2.Platform) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ByteString(com.google.protobuf.ByteString)

Example 2 with Property

use of build.bazel.remote.execution.v2.Platform.Property in project bazel-buildfarm by bazelbuild.

the class Executor method transformWrapper.

private Iterable<String> transformWrapper(ExecutionWrapper wrapper) {
    ImmutableList.Builder<String> arguments = ImmutableList.builder();
    Map<String, Property> properties = uniqueIndex(operationContext.command.getPlatform().getPropertiesList(), Property::getName);
    arguments.add(wrapper.getPath());
    for (String argument : wrapper.getArgumentsList()) {
        // the property from the platform specification.
        if (!argument.equals("<>") && argument.charAt(0) == '<' && argument.charAt(argument.length() - 1) == '>') {
            // substitute with matching platform property content
            // if this property is not present, the wrapper is ignored
            String propertyName = argument.substring(1, argument.length() - 1);
            Property property = properties.get(propertyName);
            if (property == null) {
                return ImmutableList.of();
            }
            arguments.add(property.getValue());
        } else {
            // If the argument isn't of the form <propertyName>, add the argument directly:
            arguments.add(argument);
        }
    }
    return arguments.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString) Property(build.bazel.remote.execution.v2.Platform.Property)

Example 3 with Property

use of build.bazel.remote.execution.v2.Platform.Property in project bazel-buildfarm by bazelbuild.

the class ExecutionPolicies method forPlatform.

public static Iterable<ExecutionPolicy> forPlatform(Platform platform, ExecutionPoliciesIndex policiesIndex) {
    ImmutableList.Builder<ExecutionPolicy> policies = ImmutableList.builder();
    policies.addAll(policiesIndex.get(DEFAULT_EXECUTION_POLICY_NAME));
    for (Property property : platform.getPropertiesList()) {
        if (property.getName().equals(EXECUTION_POLICY_PROPERTY_NAME) && !property.getValue().equals(DEFAULT_EXECUTION_POLICY_NAME)) {
            policies.addAll(policiesIndex.get(property.getValue()));
        }
    }
    return policies.build();
}
Also used : ExecutionPolicy(build.buildfarm.v1test.ExecutionPolicy) ImmutableList(com.google.common.collect.ImmutableList) Property(build.bazel.remote.execution.v2.Platform.Property)

Example 4 with Property

use of build.bazel.remote.execution.v2.Platform.Property in project bazel-buildfarm by bazelbuild.

the class ShardInstance method validatePlatform.

@Override
protected void validatePlatform(Platform platform, PreconditionFailure.Builder preconditionFailure) {
    int minCores = 0;
    int maxCores = -1;
    // check that the platform properties correspond to valid provisions for the OperationQeueue.
    // if the operation is eligible to be put anywhere in the OperationQueue, it passes validation.
    boolean validForOperationQueue = backplane.propertiesEligibleForQueue(platform.getPropertiesList());
    if (!validForOperationQueue) {
        preconditionFailure.addViolationsBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription(format("properties are not valid for queue eligibility: %s", platform.getPropertiesList()));
    }
    for (Property property : platform.getPropertiesList()) {
        /* FIXME generalize with config */
        if (property.getName().equals(ExecutionProperties.MIN_CORES) || property.getName().equals(ExecutionProperties.MAX_CORES)) {
            try {
                int intValue = Integer.parseInt(property.getValue());
                if (intValue <= 0 || (maxCpu != 0 && intValue > maxCpu)) {
                    preconditionFailure.addViolationsBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription(format("property '%s' value was out of range: %d", property.getName(), intValue));
                }
                if (property.getName().equals(ExecutionProperties.MIN_CORES)) {
                    minCores = intValue;
                } else {
                    maxCores = intValue;
                }
            } catch (NumberFormatException e) {
                preconditionFailure.addViolationsBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription(format("property '%s' value was not a valid integer: %s", property.getName(), property.getValue()));
            }
        }
    }
    if (maxCores != -1 && minCores > 0 && maxCores < minCores) {
        preconditionFailure.addViolationsBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription(format("%s (%d) must be >= %s (%d)", ExecutionProperties.MAX_CORES, maxCores, ExecutionProperties.MIN_CORES, minCores));
    }
}
Also used : Property(build.bazel.remote.execution.v2.Platform.Property)

Aggregations

Property (build.bazel.remote.execution.v2.Platform.Property)3 ImmutableList (com.google.common.collect.ImmutableList)2 ByteString (com.google.protobuf.ByteString)2 Platform (build.bazel.remote.execution.v2.Platform)1 ExecutionPolicy (build.buildfarm.v1test.ExecutionPolicy)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1