use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestClusterAccessor method testPartialDeleteCloudConfig.
@Test(dependsOnMethods = "testDeleteCloudConfig")
public void testPartialDeleteCloudConfig() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
ZNRecord record = new ZNRecord(clusterName);
record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.AZURE.name());
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID");
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name(), "TestProcessor");
_gSetupTool.addCluster(clusterName, true, new CloudConfig.Builder(record).build());
String urlBase = "clusters/" + clusterName + "/cloudconfig/";
Map<String, String> map = new HashMap<>();
map.put("addCloudConfig", "true");
put("clusters/" + clusterName, map, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.CREATED.getStatusCode());
// Read CloudConfig from Zookeeper and make sure it has been created
ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertNotNull(cloudConfigFromZk);
record = new ZNRecord(clusterName);
Map<String, String> map1 = new HashMap<>();
map1.put("command", Command.delete.name());
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID");
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.AZURE.name());
post(urlBase, map1, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
// Read CloudConfig from Zookeeper and make sure it has been removed
_configAccessor = new ConfigAccessor(ZK_ADDR);
cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertNull(cloudConfigFromZk.getCloudID());
Assert.assertNull(cloudConfigFromZk.getCloudProvider());
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
System.out.println("End test :" + TestHelper.getTestMethodName());
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestClusterAccessor method testUpdateCloudConfig.
@Test(dependsOnMethods = "testPartialDeleteCloudConfig")
public void testUpdateCloudConfig() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
_gSetupTool.addCluster("TestCloud", true);
String urlBase = "clusters/TestCloud/cloudconfig/";
ZNRecord record = new ZNRecord("TestCloud");
record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID");
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.AZURE.name());
// Fist add CloudConfig to the cluster
put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
// Now get the Cloud Config and make sure the information is correct
String body = get(urlBase, null, Response.Status.OK.getStatusCode(), true);
ZNRecord recordFromRest = toZNRecord(body);
CloudConfig cloudConfigRest = new CloudConfig.Builder(recordFromRest).build();
Assert.assertTrue(cloudConfigRest.isCloudEnabled());
Assert.assertEquals(cloudConfigRest.getCloudID(), "TestCloudID");
Assert.assertEquals(cloudConfigRest.getCloudProvider(), CloudProvider.AZURE.name());
// Now put new information in the ZNRecord
record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.CUSTOMIZED.name());
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudIdNew");
List<String> testList = new ArrayList<String>();
testList.add("TestURL");
record.setListField(CloudConfig.CloudConfigProperty.CLOUD_INFO_SOURCE.name(), testList);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name(), "TestProcessorName");
Map<String, String> map1 = new HashMap<>();
map1.put("command", AbstractResource.Command.update.name());
post(urlBase, map1, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
// Now get the Cloud Config and make sure the information has been updated
body = get(urlBase, null, Response.Status.OK.getStatusCode(), true);
recordFromRest = toZNRecord(body);
cloudConfigRest = new CloudConfig.Builder(recordFromRest).build();
Assert.assertTrue(cloudConfigRest.isCloudEnabled());
Assert.assertEquals(cloudConfigRest.getCloudID(), "TestCloudIdNew");
Assert.assertEquals(cloudConfigRest.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
List<String> listUrlFromRest = cloudConfigRest.getCloudInfoSources();
Assert.assertEquals(listUrlFromRest.get(0), "TestURL");
Assert.assertEquals(cloudConfigRest.getCloudInfoProcessorName(), "TestProcessorName");
System.out.println("End test :" + TestHelper.getTestMethodName());
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestClusterAccessor method testAddCloudConfig.
@Test(dependsOnMethods = "testAddCloudConfigNonExistedCluster")
public void testAddCloudConfig() throws Exception {
System.out.println("Start test :" + TestHelper.getTestMethodName());
_gSetupTool.addCluster("TestCloud", true);
String urlBase = "clusters/TestCloud/cloudconfig/";
ZNRecord record = new ZNRecord("TestCloud");
record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.CUSTOMIZED.name());
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID");
List<String> testList = new ArrayList<String>();
testList.add("TestURL");
record.setListField(CloudConfig.CloudConfigProperty.CLOUD_INFO_SOURCE.name(), testList);
// Bad request since Processor has not been defined.
put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.BAD_REQUEST.getStatusCode());
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name(), "TestProcessorName");
// Now response should be OK since all fields are set
put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
// Read CloudConfig from Zookeeper and check the content
ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig("TestCloud");
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessorName");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
// Now test the getCloudConfig method.
String body = get(urlBase, null, Response.Status.OK.getStatusCode(), true);
ZNRecord recordFromRest = toZNRecord(body);
CloudConfig cloudConfigRest = new CloudConfig.Builder(recordFromRest).build();
CloudConfig cloudConfigZk = _configAccessor.getCloudConfig("TestCloud");
// Check that the CloudConfig from Zk and REST get method are equal
Assert.assertEquals(cloudConfigRest, cloudConfigZk);
// Check the fields individually
Assert.assertTrue(cloudConfigRest.isCloudEnabled());
Assert.assertEquals(cloudConfigRest.getCloudID(), "TestCloudID");
Assert.assertEquals(cloudConfigRest.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
List<String> listUrlFromRest = cloudConfigRest.getCloudInfoSources();
Assert.assertEquals(listUrlFromRest.get(0), "TestURL");
Assert.assertEquals(cloudConfigRest.getCloudInfoProcessorName(), "TestProcessorName");
System.out.println("End test :" + TestHelper.getTestMethodName());
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestVirtualTopologyGroupService method prepare.
@BeforeTest
public void prepare() {
Map<String, Set<String>> assignment = new HashMap<>();
_instanceConfig0 = new InstanceConfig("instance_0");
_instanceConfig0.setDomain("helixZoneId=zone0");
_instanceConfig1 = new InstanceConfig("instance_1");
_instanceConfig1.setDomain("helixZoneId=zone0");
_instanceConfig2 = new InstanceConfig("instance_2");
_instanceConfig2.setDomain("helixZoneId=zone1");
assignment.put("virtual_group_0", ImmutableSet.of("instance_0", "instance_1"));
assignment.put("virtual_group_1", ImmutableSet.of("instance_2"));
_updaterMap = VirtualTopologyGroupService.createInstanceConfigUpdater(TEST_CLUSTER, assignment);
ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER0);
clusterConfig.setFaultZoneType(AzureConstants.AZURE_FAULT_ZONE_TYPE);
clusterConfig.setTopology(AzureConstants.AZURE_TOPOLOGY);
clusterConfig.setTopologyAwareEnabled(true);
when(_configAccessor.getClusterConfig(TEST_CLUSTER0)).thenReturn(clusterConfig);
CloudConfig.Builder cloudConfigBuilder = new CloudConfig.Builder();
cloudConfigBuilder.setCloudEnabled(true);
cloudConfigBuilder.setCloudProvider(CloudProvider.AZURE);
cloudConfigBuilder.setCloudID("TestID");
CloudConfig cloudConfig = cloudConfigBuilder.build();
when(_configAccessor.getCloudConfig(TEST_CLUSTER0)).thenReturn(cloudConfig);
_helixAdmin = mock(HelixAdmin.class);
when(_helixAdmin.isInMaintenanceMode(anyString())).thenReturn(true);
boolean[] results = new boolean[2];
results[0] = results[1] = true;
when(_dataAccessor.updateChildren(anyList(), anyList(), anyInt())).thenReturn(results);
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.getClusterTopology(anyString())).thenReturn(prepareClusterTopology());
_service = new VirtualTopologyGroupService(_helixAdmin, clusterService, _configAccessor, _dataAccessor);
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ConfigAccessor method getCloudConfig.
/**
* Get CloudConfig of the given cluster.
* @param clusterName
* @return The instance of {@link CloudConfig}
*/
public CloudConfig getCloudConfig(String clusterName) {
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException(String.format("Failed to get config. cluster: %s is not setup.", clusterName));
}
HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLOUD).forCluster(clusterName).build();
ZNRecord record = getConfigZnRecord(scope);
if (record == null) {
LOG.warn("No cloud config found at {}.", scope.getZkPath());
return null;
}
return new CloudConfig(record);
}
Aggregations