org.cloudfoundry.client.lib.adapters.RawCloudTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudfoundry-client-lib Show documentation
Show all versions of cloudfoundry-client-lib Show documentation
A Cloud Foundry client library for Java
The newest version!
package org.cloudfoundry.client.lib.adapters;
import java.util.Optional;
import org.cloudfoundry.client.lib.domain.CloudTask;
import org.cloudfoundry.client.lib.domain.ImmutableCloudTask;
import org.cloudfoundry.client.v3.tasks.Result;
import org.cloudfoundry.client.v3.tasks.Task;
import org.cloudfoundry.client.v3.tasks.TaskState;
import org.immutables.value.Value;
@Value.Immutable
public abstract class RawCloudTask extends RawCloudEntity {
@Value.Parameter
public abstract Task getResource();
@Override
public CloudTask derive() {
Task resource = getResource();
return ImmutableCloudTask.builder()
.metadata(parseResourceMetadata(resource))
.name(resource.getName())
.command(resource.getCommand())
.limits(parseLimits(resource))
.result(parseResult(resource))
.state(parseState(resource.getState()))
.build();
}
private static CloudTask.Result parseResult(Task resource) {
return Optional.ofNullable(resource.getResult())
.map(Result::getFailureReason)
.map(ImmutableCloudTask.ImmutableResult::of)
.orElse(null);
}
private static CloudTask.Limits parseLimits(Task resource) {
return ImmutableCloudTask.ImmutableLimits.builder()
.disk(resource.getDiskInMb())
.memory(resource.getMemoryInMb())
.build();
}
private static CloudTask.State parseState(TaskState state) {
return parseEnum(state, CloudTask.State.class);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy