Search in sources :

Example 1 with AgentWriteConfigurationSetResponse

use of alluxio.hub.proto.AgentWriteConfigurationSetResponse 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)

Aggregations

AlluxioException (alluxio.exception.AlluxioException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 AgentWriteConfigurationSetResponse (alluxio.hub.proto.AgentWriteConfigurationSetResponse)1 HubNodeAddress (alluxio.hub.proto.HubNodeAddress)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteString (com.google.protobuf.ByteString)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1