use of io.fabric8.support.api.Resource in project camel by apache.
the class KubernetesServicesProducer method doListServiceByLabels.
protected void doListServiceByLabels(Exchange exchange, String operation) throws Exception {
ServiceList servicesList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
services = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
services.withLabel(entry.getKey(), entry.getValue());
}
servicesList = services.list();
} else {
MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
services = getEndpoint().getKubernetesClient().services();
for (Map.Entry<String, String> entry : labels.entrySet()) {
services.withLabel(entry.getKey(), entry.getValue());
}
servicesList = services.list();
}
exchange.getOut().setBody(servicesList.getItems());
}
use of io.fabric8.support.api.Resource in project docker-maven-plugin by fabric8io.
the class DockerFileUtilTest method copyToTempDir.
private File copyToTempDir(String resource) throws IOException {
File dir = Files.createTempDirectory("d-m-p").toFile();
File ret = new File(dir, "Dockerfile");
try (FileOutputStream os = new FileOutputStream(ret)) {
IOUtil.copy(getClass().getResourceAsStream(resource), os);
}
return ret;
}
use of io.fabric8.support.api.Resource in project camel by apache.
the class KubernetesResourcesQuotaProducer method doCreateResourceQuota.
protected void doCreateResourceQuota(Exchange exchange, String operation) throws Exception {
ResourceQuota rq = null;
String rqName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
ResourceQuotaSpec rqSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC, ResourceQuotaSpec.class);
if (ObjectHelper.isEmpty(rqName)) {
LOG.error("Create a specific resource quota require specify a resource quota name");
throw new IllegalArgumentException("Create a specific resource quota require specify a resource quota name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific resource quota require specify a namespace name");
throw new IllegalArgumentException("Create a specific resource quota require specify a namespace name");
}
if (ObjectHelper.isEmpty(rqSpec)) {
LOG.error("Create a specific resource quota require specify a resource quota spec bean");
throw new IllegalArgumentException("Create a specific resource quota require specify a resource quota spec bean");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, Map.class);
ResourceQuota rqCreating = new ResourceQuotaBuilder().withNewMetadata().withName(rqName).withLabels(labels).endMetadata().withSpec(rqSpec).build();
rq = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName).create(rqCreating);
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(rq);
}
use of io.fabric8.support.api.Resource in project camel by apache.
the class KubernetesResourcesQuotaProducer method doListResourceQuotasByLabels.
protected void doListResourceQuotasByLabels(Exchange exchange, String operation) throws Exception {
ResourceQuotaList resList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
resQuota = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
resQuota.withLabel(entry.getKey(), entry.getValue());
}
resList = resQuota.list();
} else {
MixedOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
resQuota = getEndpoint().getKubernetesClient().resourceQuotas();
for (Map.Entry<String, String> entry : labels.entrySet()) {
resQuota.withLabel(entry.getKey(), entry.getValue());
}
resList = resQuota.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(resList.getItems());
}
use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class DeploymentAgent method updateStatus.
private void updateStatus(FabricService fs, String status, Throwable result, boolean force) /*=false*/
{
if (!force && System.currentTimeMillis() < lastStatusUpdate + UPDATE_INTERVAL) {
return;
}
lastStatusUpdate = System.currentTimeMillis();
try {
provisioningStatus = status;
provisioningError = result;
if (fs != null) {
fabricNotAvailableLogged = false;
Container container = fs.getCurrentContainer();
String e;
if (result == null) {
e = null;
} else {
StringWriter sw = new StringWriter();
result.printStackTrace(new PrintWriter(sw));
e = sw.toString();
}
if (provisionList != null) {
Set<String> uris = new TreeSet<>();
for (Resource res : provisionList) {
uris.add(getUri(res));
}
container.setProvisionList(new ArrayList<>(uris));
}
container.setProvisionResult(status);
container.setProvisionException(e);
java.util.Properties provisionChecksums = new java.util.Properties();
for (Map.Entry<Long, Long> entry : state.bundleChecksums.entrySet()) {
Bundle bundle = systemBundleContext.getBundle(entry.getKey());
String location = bundle.getLocation();
provisionChecksums.put(location, entry.getValue().toString());
}
/*
putAllProperties(provisionChecksums, libChecksums);
putAllProperties(provisionChecksums, endorsedChecksums);
putAllProperties(provisionChecksums, extensionChecksums);
*/
container.setProvisionChecksums(provisionChecksums);
} else {
if (!fabricNotAvailableLogged) {
fabricNotAvailableLogged = true;
LOGGER.info("Unable to set provisioning status as FabricService is not available");
}
}
} catch (Throwable e) {
LOGGER.warn("Unable to set provisioning result");
}
}
Aggregations