Search in sources :

Example 6 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress 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 7 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContext method configurationSetFor.

/**
 * Gets the configuration for a given alluxio node type.
 *
 * @param type the type of node to get the configuration from
 * @return a mapping of responses from each hub agent the action was executed on to the
 *         agent's address
 */
public AlluxioConfigurationSet configurationSetFor(AlluxioNodeType type) {
    Set<HubNodeAddress> nodes = mHubCluster.nodesFromAlluxio(mAlluxioCluster, type);
    Iterator<HubNodeAddress> iter = nodes.iterator();
    if (!iter.hasNext()) {
        throw new IllegalStateException("No nodes of type " + type + " to get configuration in the " + "cluster.");
    }
    HubNodeAddress addr = iter.next();
    Map<HubNodeAddress, AlluxioConfigurationSet> confSet = mHubCluster.exec(Collections.singleton(addr), mConf, (client) -> client.getConfigurationSet(AgentGetConfigurationSetRequest.newBuilder().build()).getConfSet(), mSvc);
    return confSet.get(addr);
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AlluxioConfigurationSet(alluxio.hub.proto.AlluxioConfigurationSet)

Example 8 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContextTest method testAddFile.

@Test
public void testAddFile() {
    AgentFileUploadResponse r = AgentFileUploadResponse.newBuilder().setSuccess(true).setVersion(2).setFileName("uptime").build();
    HubNodeAddress addr = HubTestUtils.generateNodeAddress();
    Map<HubNodeAddress, AgentFileUploadResponse> resp = new HashMap<>();
    resp.put(addr, r);
    UploadFile req = UploadFile.newBuilder().setDestination(AlluxioNodeType.WORKER).setProcessType(UploadProcessType.PRESTO).setContent("#!/usr/bin/env bash\nuptime").setName("uptime").setPermission("0777").build();
    doReturn(resp).when(mContext).execOnHub(any(), any(), any());
    boolean addFileResp = mContext.uploadFile(Collections.singletonList(req));
    assertTrue(addFileResp);
    resp.put(HubTestUtils.generateNodeAddress(), r.toBuilder().setSuccess(false).build());
    assertFalse(mContext.uploadFile(Collections.singletonList(req)));
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) UploadFile(alluxio.hub.proto.UploadFile) HashMap(java.util.HashMap) AgentFileUploadResponse(alluxio.hub.proto.AgentFileUploadResponse) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 9 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContextTest method testListCatalogs.

@Test
public void testListCatalogs() throws IOException {
    Set<String> nodes = Collections.singleton(UUID.randomUUID().toString());
    doReturn(nodes).when(mMockHub).nodesFromAlluxio(mMockAlluxio, AlluxioNodeType.MASTER);
    Path prestoCatalogDir = Paths.get(mTemp.getRoot().getAbsolutePath(), "etc/presto/conf/catalog");
    Files.createDirectories(prestoCatalogDir);
    PrestoCatalogListing r = PrestoCatalogListing.newBuilder().setCatalogName("hive-test").setHiveMetastoreUri("thrift://blahblahblah:9083").build();
    Map<HubNodeAddress, AgentListCatalogResponse> map = new HashMap<>();
    map.put(HubNodeAddress.newBuilder().build(), AgentListCatalogResponse.newBuilder().addCatalog(r).build());
    doReturn(map).when(mMockHub).exec(any(), any(), any(), any());
    assertEquals(PrestoCatalogListingResult.newBuilder().addCatalog(r).build(), mContext.listCatalogs(prestoCatalogDir.toString()));
}
Also used : Path(java.nio.file.Path) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) PrestoCatalogListing(alluxio.hub.proto.PrestoCatalogListing) HashMap(java.util.HashMap) AgentListCatalogResponse(alluxio.hub.proto.AgentListCatalogResponse) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 10 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContextTest method testExecOnHubEmpty.

@Test
public void testExecOnHubEmpty() {
    Set<HubNodeAddress> nodes = Collections.singleton(HubNodeAddress.newBuilder().setHostname(UUID.randomUUID().toString()).build());
    doReturn(nodes).when(mMockHub).nodesFromAlluxio(mMockAlluxio, AlluxioNodeType.MASTER);
    AtomicInteger i = new AtomicInteger(0);
    Function<AgentManagerServiceGrpc.AgentManagerServiceBlockingStub, Integer> action = client -> i.get();
    mContext.execOnHub(action, AlluxioNodeType.MASTER);
    verify(mMockHub).nodesFromAlluxio(mMockAlluxio, AlluxioNodeType.MASTER);
    verify(mMockHub).exec(nodes, mConf, action, mMockExec);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AlluxioCluster(alluxio.hub.manager.util.AlluxioCluster) AgentListFileResponse(alluxio.hub.proto.AgentListFileResponse) AlluxioConfigurationSet(alluxio.hub.proto.AlluxioConfigurationSet) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RemoveFile(alluxio.hub.proto.RemoveFile) SpeedTestResponse(alluxio.hub.proto.SpeedTestResponse) ValidationTaskResult(alluxio.cli.ValidationTaskResult) PropertyKey(alluxio.conf.PropertyKey) UploadFile(alluxio.hub.proto.UploadFile) IOTaskSummary(alluxio.stress.worker.IOTaskSummary) AgentListFileInfo(alluxio.hub.proto.AgentListFileInfo) AgentRemoveFileResponse(alluxio.hub.proto.AgentRemoveFileResponse) FileSystem(alluxio.client.file.FileSystem) SpeedTestRequest(alluxio.hub.proto.SpeedTestRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AgentFileUploadResponse(alluxio.hub.proto.AgentFileUploadResponse) After(org.junit.After) Map(java.util.Map) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(java.nio.file.Path) HubTestUtils(alluxio.hub.manager.util.HubTestUtils) UploadProcessType(alluxio.hub.proto.UploadProcessType) HubCluster(alluxio.hub.manager.util.HubCluster) ValidationUtils(alluxio.cli.ValidationUtils) Set(java.util.Set) UUID(java.util.UUID) SetPrestoConfDirRequest(alluxio.hub.proto.SetPrestoConfDirRequest) BaseHubTest(alluxio.hub.test.BaseHubTest) List(java.util.List) SetPrestoConfDirResponse(alluxio.hub.proto.SetPrestoConfDirResponse) Assert.assertFalse(org.junit.Assert.assertFalse) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) MountPointInfo(alluxio.wire.MountPointInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertThrows(org.junit.Assert.assertThrows) ValidationResult(alluxio.hub.proto.ValidationResult) HashMap(java.util.HashMap) AgentManagerServiceGrpc(alluxio.hub.proto.AgentManagerServiceGrpc) Function(java.util.function.Function) SpeedStat(alluxio.hub.proto.SpeedStat) ArrayList(java.util.ArrayList) AgentListCatalogResponse(alluxio.hub.proto.AgentListCatalogResponse) AlluxioNodeType(alluxio.hub.proto.AlluxioNodeType) PrestoCatalogListingResult(alluxio.hub.proto.PrestoCatalogListingResult) UfsIOBench(alluxio.stress.cli.UfsIOBench) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) ListMountPointResponse(alluxio.hub.proto.ListMountPointResponse) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) ListFile(alluxio.hub.proto.ListFile) Before(org.junit.Before) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) PrestoCatalogListing(alluxio.hub.proto.PrestoCatalogListing) ApplyMountPointRequest(alluxio.hub.proto.ApplyMountPointRequest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Pair(alluxio.collections.Pair) Mockito.verify(org.mockito.Mockito.verify) ApplyMountPointResponse(alluxio.hub.proto.ApplyMountPointResponse) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) Paths(java.nio.file.Paths) ValidationStatus(alluxio.hub.proto.ValidationStatus) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HubUtil(alluxio.hub.common.HubUtil) SpeedTestParameter(alluxio.hub.proto.SpeedTestParameter) TemporaryFolder(org.junit.rules.TemporaryFolder) AgentSetPrestoConfResponse(alluxio.hub.proto.AgentSetPrestoConfResponse) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Aggregations

HubNodeAddress (alluxio.hub.proto.HubNodeAddress)17 BaseHubTest (alluxio.hub.test.BaseHubTest)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)6 Map (java.util.Map)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Pair (alluxio.collections.Pair)2 AgentFileUploadResponse (alluxio.hub.proto.AgentFileUploadResponse)2 AgentListCatalogResponse (alluxio.hub.proto.AgentListCatalogResponse)2 AlluxioConfigurationSet (alluxio.hub.proto.AlluxioConfigurationSet)2 AlluxioNodeType (alluxio.hub.proto.AlluxioNodeType)2 PrestoCatalogListing (alluxio.hub.proto.PrestoCatalogListing)2 UploadFile (alluxio.hub.proto.UploadFile)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2