use of com.mesosphere.sdk.offer.evaluate.placement.PassthroughRule in project dcos-commons by mesosphere.
the class YAMLToInternalMappers method convertPod.
private static PodSpec convertPod(RawPod rawPod, ConfigTemplateReader configTemplateReader, String podName, Map<String, String> additionalEnv, String role, String principal, String executorUri, String user) throws Exception {
DefaultPodSpec.Builder builder = DefaultPodSpec.newBuilder(executorUri).count(rawPod.getCount()).type(podName).user(user).preReservedRole(rawPod.getPreReservedRole()).sharePidNamespace(rawPod.getSharePidNamespace()).allowDecommission(rawPod.getAllowDecommission());
List<String> networkNames = new ArrayList<>();
List<RLimitSpec> rlimits = new ArrayList<>();
for (Map.Entry<String, RawRLimit> entry : rawPod.getRLimits().entrySet()) {
RawRLimit rawRLimit = entry.getValue();
rlimits.add(new RLimitSpec(entry.getKey(), rawRLimit.getSoft(), rawRLimit.getHard()));
}
WriteOnceLinkedHashMap<String, RawNetwork> rawNetworks = rawPod.getNetworks();
final Collection<NetworkSpec> networks = new ArrayList<>();
if (MapUtils.isNotEmpty(rawNetworks)) {
networks.addAll(rawNetworks.entrySet().stream().map(rawNetworkEntry -> {
String networkName = rawNetworkEntry.getKey();
DcosConstants.warnIfUnsupportedNetwork(networkName);
networkNames.add(networkName);
RawNetwork rawNetwork = rawNetworks.get(networkName);
return convertNetwork(networkName, rawNetwork, collatePorts(rawPod));
}).collect(Collectors.toList()));
}
builder.image(rawPod.getImage()).networks(networks).rlimits(rlimits);
// Collect the resourceSets (if given)
final Collection<ResourceSet> resourceSets = new ArrayList<>();
WriteOnceLinkedHashMap<String, RawResourceSet> rawResourceSets = rawPod.getResourceSets();
if (MapUtils.isNotEmpty(rawResourceSets)) {
resourceSets.addAll(rawResourceSets.entrySet().stream().map(rawResourceSetEntry -> {
String rawResourceSetName = rawResourceSetEntry.getKey();
RawResourceSet rawResourceSet = rawResourceSets.get(rawResourceSetName);
return convertResourceSet(rawResourceSetName, rawResourceSet.getCpus(), rawResourceSet.getGpus(), rawResourceSet.getMemory(), rawResourceSet.getPorts(), rawResourceSet.getVolume(), rawResourceSet.getVolumes(), role, rawPod.getPreReservedRole(), principal, networkNames);
}).collect(Collectors.toList()));
}
if (!rawPod.getSecrets().isEmpty()) {
Collection<SecretSpec> secretSpecs = new ArrayList<>();
secretSpecs.addAll(rawPod.getSecrets().values().stream().map(v -> convertSecret(v)).collect(Collectors.toList()));
builder.secrets(secretSpecs);
}
if (rawPod.getVolume() != null || !rawPod.getVolumes().isEmpty()) {
Collection<VolumeSpec> volumeSpecs = new ArrayList<>(rawPod.getVolume() == null ? Collections.emptyList() : Arrays.asList(convertVolume(rawPod.getVolume(), role, rawPod.getPreReservedRole(), principal)));
volumeSpecs.addAll(rawPod.getVolumes().values().stream().map(v -> convertVolume(v, role, rawPod.getPreReservedRole(), principal)).collect(Collectors.toList()));
builder.volumes(volumeSpecs);
}
// Parse the TaskSpecs
List<TaskSpec> taskSpecs = new ArrayList<>();
for (Map.Entry<String, RawTask> entry : rawPod.getTasks().entrySet()) {
taskSpecs.add(convertTask(entry.getValue(), configTemplateReader, entry.getKey(), additionalEnv, resourceSets, role, rawPod.getPreReservedRole(), principal, networkNames));
}
builder.tasks(taskSpecs);
Collection<URI> podUris = new ArrayList<>();
for (String uriStr : rawPod.getUris()) {
podUris.add(new URI(uriStr));
}
builder.uris(podUris);
PlacementRule placementRule = MarathonConstraintParser.parse(podName, rawPod.getPlacement());
if (!(placementRule instanceof PassthroughRule)) {
builder.placementRule(placementRule);
}
return builder.build();
}
Aggregations