use of io.fabric8.openshift.api.model.Template in project syndesis-qe by syndesisio.
the class WildFlyS2i method deploy.
@Override
public void deploy() {
if (!isDeployed()) {
Template template;
try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-wildfly.yml")) {
template = OpenShiftUtils.getInstance().templates().load(is).get();
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to read template ", ex);
}
Map<String, String> templateParams = new HashMap<>();
templateParams.put("GITHUB_REPO", gitURL);
templateParams.put("APPLICATION_NAME", appName);
templateParams.put("SOURCE_REF", branch == null ? "master" : branch);
OpenShiftUtils.getInstance().templates().withName(appName).delete();
OpenShiftUtils.getInstance().imageStreams().createOrReplaceWithNew().editOrNewMetadata().withName("wildfly-130-centos7").addToLabels("app", appName).endMetadata().editOrNewSpec().editOrNewLookupPolicy().withLocal(false).endLookupPolicy().addNewTag().addToAnnotations("openshift.io/imported-from", "quay.io/syndesis_qe/wildfly-130-centos7").editOrNewFrom().withKind("DockerImage").withName("quay.io/syndesis_qe/wildfly-130-centos7").endFrom().withName("latest").editOrNewReferencePolicy().withType("Source").endReferencePolicy().endTag().endSpec().done();
OpenShiftUtils.getInstance().createResources(OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams));
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.
the class Controller method doCreateTemplate.
protected void doCreateTemplate(Template entity, String namespace, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.TEMPLATE)) {
LOG.info("Creating a Template from " + sourceName + " namespace " + namespace + " name " + getName(entity));
try {
Object answer = openShiftClient.templates().inNamespace(namespace).create(entity);
logGeneratedEntity("Created Template: ", namespace, entity, answer);
} catch (Exception e) {
onApplyError("Failed to Template entity from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.
the class Controller method installTemplate.
/**
* Installs the template into the namespace without processing it
*/
public void installTemplate(Template entity, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient == null || !openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.TEMPLATE)) {
// lets not install the template on Kubernetes!
return;
}
if (!isProcessTemplatesLocally()) {
String namespace = getNamespace();
String id = getName(entity);
Objects.notNull(id, "No name for " + entity + " " + sourceName);
Template old = openShiftClient.templates().inNamespace(namespace).withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(entity, old)) {
LOG.info("Template has not changed so not doing anything");
} else {
boolean recreateMode = isRecreateMode();
// TODO seems you can't update templates right now
recreateMode = true;
if (recreateMode) {
openShiftClient.templates().inNamespace(namespace).withName(id).delete();
doCreateTemplate(entity, namespace, sourceName);
} else {
LOG.info("Updating a Template from " + sourceName);
try {
Object answer = openShiftClient.templates().inNamespace(namespace).withName(id).replace(entity);
LOG.info("Updated Template: " + answer);
} catch (Exception e) {
onApplyError("Failed to update Template from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
} else {
if (!isAllowCreate()) {
LOG.warn("Creation disabled so not creating a Template from " + sourceName + " namespace " + namespace + " name " + getName(entity));
} else {
doCreateTemplate(entity, namespace, sourceName);
}
}
}
}
use of io.fabric8.openshift.api.model.Template in project flink by apache.
the class KubernetesUtils method getResourceRequirements.
/**
* Get resource requirements from memory and cpu.
*
* @param resourceRequirements resource requirements in pod template
* @param mem Memory in mb.
* @param memoryLimitFactor limit factor for the memory, used to set the limit resources.
* @param cpu cpu.
* @param cpuLimitFactor limit factor for the cpu, used to set the limit resources.
* @param externalResources external resources
* @param externalResourceConfigKeys config keys of external resources
* @return KubernetesResource requirements.
*/
public static ResourceRequirements getResourceRequirements(ResourceRequirements resourceRequirements, int mem, double memoryLimitFactor, double cpu, double cpuLimitFactor, Map<String, ExternalResource> externalResources, Map<String, String> externalResourceConfigKeys) {
final Quantity cpuQuantity = new Quantity(String.valueOf(cpu));
final Quantity cpuLimitQuantity = new Quantity(String.valueOf(cpu * cpuLimitFactor));
final Quantity memQuantity = new Quantity(mem + Constants.RESOURCE_UNIT_MB);
final Quantity memQuantityLimit = new Quantity(((int) (mem * memoryLimitFactor)) + Constants.RESOURCE_UNIT_MB);
ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder(resourceRequirements).addToRequests(Constants.RESOURCE_NAME_MEMORY, memQuantity).addToRequests(Constants.RESOURCE_NAME_CPU, cpuQuantity).addToLimits(Constants.RESOURCE_NAME_MEMORY, memQuantityLimit).addToLimits(Constants.RESOURCE_NAME_CPU, cpuLimitQuantity);
// Add the external resources to resource requirement.
for (Map.Entry<String, ExternalResource> externalResource : externalResources.entrySet()) {
final String configKey = externalResourceConfigKeys.get(externalResource.getKey());
if (!StringUtils.isNullOrWhitespaceOnly(configKey)) {
final Quantity resourceQuantity = new Quantity(String.valueOf(externalResource.getValue().getValue().longValue()));
resourceRequirementsBuilder.addToRequests(configKey, resourceQuantity).addToLimits(configKey, resourceQuantity);
LOG.info("Request external resource {} with config key {}.", resourceQuantity.getAmount(), configKey);
}
}
return resourceRequirementsBuilder.build();
}
use of io.fabric8.openshift.api.model.Template in project flink by apache.
the class KubernetesUtils method loadPodFromTemplateFile.
public static FlinkPod loadPodFromTemplateFile(FlinkKubeClient kubeClient, File podTemplateFile, String mainContainerName) {
final KubernetesPod pod = kubeClient.loadPodFromTemplateFile(podTemplateFile);
final List<Container> otherContainers = new ArrayList<>();
Container mainContainer = null;
for (Container container : pod.getInternalResource().getSpec().getContainers()) {
if (mainContainerName.equals(container.getName())) {
mainContainer = container;
} else {
otherContainers.add(container);
}
}
if (mainContainer == null) {
LOG.info("Could not find main container {} in pod template, using empty one to initialize.", mainContainerName);
mainContainer = new ContainerBuilder().build();
}
pod.getInternalResource().getSpec().setContainers(otherContainers);
return new FlinkPod(pod.getInternalResource(), mainContainer);
}
Aggregations