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();
}
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();
}
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());
}
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());
}
}
}
}
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());
}
Aggregations