Search in sources :

Example 76 with Resource

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());
}
Also used : DoneableService(io.fabric8.kubernetes.api.model.DoneableService) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service) Map(java.util.Map)

Example 77 with Resource

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;
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile)

Example 78 with Resource

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);
}
Also used : DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ResourceQuotaSpec(io.fabric8.kubernetes.api.model.ResourceQuotaSpec) ResourceQuotaBuilder(io.fabric8.kubernetes.api.model.ResourceQuotaBuilder)

Example 79 with Resource

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());
}
Also used : ResourceQuotaList(io.fabric8.kubernetes.api.model.ResourceQuotaList) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) Map(java.util.Map)

Example 80 with Resource

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");
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Resource(org.osgi.resource.Resource) Properties(org.apache.felix.utils.properties.Properties) Container(io.fabric8.api.Container) StringWriter(java.io.StringWriter) TreeSet(java.util.TreeSet) Map(java.util.Map) HashMap(java.util.HashMap) PrintWriter(java.io.PrintWriter)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7