Search in sources :

Example 66 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project strimzi by strimzi.

the class TopicSerialization method toJson.

/**
 * Returns the UTF-8 encoded JSON to reflect the given Topic.
 * This is what is stored in the znodes owned by the {@link ZkTopicStore}.
 */
public static byte[] toJson(Topic topic) {
    ObjectMapper mapper = objectMapper();
    ObjectNode root = mapper.createObjectNode();
    // TODO Do we store the k8s uid here?
    root.put(JSON_KEY_MAP_NAME, topic.getOrAsMapName().toString());
    root.put(JSON_KEY_TOPIC_NAME, topic.getTopicName().toString());
    root.put(JSON_KEY_PARTITIONS, topic.getNumPartitions());
    root.put(JSON_KEY_REPLICAS, topic.getNumReplicas());
    ObjectNode config = mapper.createObjectNode();
    for (Map.Entry<String, String> entry : topic.getConfig().entrySet()) {
        config.put(entry.getKey(), entry.getValue());
    }
    root.set(JSON_KEY_CONFIG, config);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        mapper.writeValue(baos, root);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 67 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project alluxio by Alluxio.

the class ManagerProcessContext method updateConfigurationFor.

/**
 * Updates the configuration for a set of Alluxio nodes.
 *
 * @param type the type of node to write the configuration to
 * @param conf the configuration to write
 * @return a set of the nodes which had their configuration updated
 */
public Set<HubNodeAddress> updateConfigurationFor(AlluxioNodeType type, AlluxioConfigurationSet conf) {
    Set<HubNodeAddress> nodes = mHubCluster.nodesFromAlluxio(mAlluxioCluster, type);
    Map<HubNodeAddress, AgentWriteConfigurationSetResponse> confSet = mHubCluster.exec(nodes, mConf, (client) -> client.writeConfigurationSet(AgentWriteConfigurationSetRequest.newBuilder().setConfSet(conf).build()), mSvc);
    // update the file system client to reflect the new conf
    if (type.equals(AlluxioNodeType.MASTER)) {
        updateFileSystemClient(conf);
    }
    // if running in K8s, update configmap
    if (mK8sConfig != null && (type.equals(AlluxioNodeType.MASTER) || type.equals(AlluxioNodeType.ALL))) {
        // We maintain a single configMap for all pods, so the config set is symmetric
        LOG.info("Persist configuration to K8s configMap {}", mK8sConfigMapName);
        try (KubernetesClient client = new DefaultKubernetesClient(mK8sConfig)) {
            String namespace = client.getNamespace();
            if (namespace == null) {
                LOG.info("Use K8s default namespace ");
                namespace = "default";
            }
            // Update configMap
            ConfigMap existingConfig = client.configMaps().inNamespace(namespace).withName(mK8sConfigMapName).get();
            if (existingConfig != null) {
                ConfigMapBuilder builder = new ConfigMapBuilder().withMetadata(existingConfig.getMetadata()).withData(existingConfig.getData());
                // Replace log4 properties
                builder.addToData(K8S_CONFIG_MAP_ENV_LOG4J, conf.getLog4JProperties());
                // Replace site properties
                builder.addToData(K8S_CONFIG_MAP_ENV_SITE, conf.getSiteProperties());
                // Replace environment variables
                for (Map.Entry<String, String> entry : HubUtil.getEnvVarsFromFile(conf.getAlluxioEnv(), LOG).entrySet()) {
                    builder.addToData(entry.getKey(), entry.getValue());
                }
                // Write config map
                client.configMaps().inNamespace(namespace).withName(mK8sConfigMapName).replace(builder.build());
                LOG.info("Updated K8s configMap {}", mK8sConfigMapName);
            }
        } catch (Exception e) {
            LOG.error("Unable to persist configuration to K8s configMap {}", mK8sConfigMapName, e);
        }
    }
    return confSet.keySet();
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) AgentWriteConfigurationSetResponse(alluxio.hub.proto.AgentWriteConfigurationSetResponse) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ByteString(com.google.protobuf.ByteString) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException)

Example 68 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry 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 69 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.

the class StartMojo method exposeContainerProps.

// Expose ports as project properties
private void exposeContainerProps(QueryService queryService, StartedContainer startedContainer) throws DockerAccessException {
    String propKey = getExposedPropertyKeyPart(startedContainer.imageConfig);
    if (StringUtils.isNotEmpty(exposeContainerProps) && StringUtils.isNotEmpty(propKey)) {
        Container container = queryService.getMandatoryContainer(startedContainer.containerId);
        Properties props = project.getProperties();
        String prefix = addDot(exposeContainerProps) + addDot(propKey);
        props.put(prefix + "id", startedContainer.containerId);
        String ip = container.getIPAddress();
        if (StringUtils.isNotEmpty(ip)) {
            props.put(prefix + "ip", ip);
        }
        Map<String, String> nets = container.getCustomNetworkIpAddresses();
        if (nets != null) {
            for (Map.Entry<String, String> entry : nets.entrySet()) {
                props.put(prefix + addDot("net") + addDot(entry.getKey()) + "ip", entry.getValue());
            }
        }
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container)

Example 70 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project camel by apache.

the class KubernetesBuildConfigsProducer method doListBuildConfigsByLabels.

protected void doListBuildConfigsByLabels(Exchange exchange, String operation) throws Exception {
    BuildConfigList buildConfigsList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    } else {
        MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildConfigsList.getItems());
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfigResource(io.fabric8.openshift.client.dsl.BuildConfigResource) Map(java.util.Map) BuildConfigList(io.fabric8.openshift.api.model.BuildConfigList)

Aggregations

Map (java.util.Map)89 HashMap (java.util.HashMap)57 IOException (java.io.IOException)31 File (java.io.File)30 ArrayList (java.util.ArrayList)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)16 List (java.util.List)14 Properties (java.util.Properties)14 HashSet (java.util.HashSet)10 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)9 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)9 Test (org.junit.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 LinkedHashMap (java.util.LinkedHashMap)8 TreeMap (java.util.TreeMap)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)7 FileInputStream (java.io.FileInputStream)7 Set (java.util.Set)7 Profile (io.fabric8.api.Profile)6 ProfileService (io.fabric8.api.ProfileService)5