use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ClusterAccessor method createCluster.
@NamespaceAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@PUT
@Path("{clusterId}")
public Response createCluster(@PathParam("clusterId") String clusterId, @DefaultValue("false") @QueryParam("recreate") String recreate, @DefaultValue("false") @QueryParam("addCloudConfig") String addCloudConfig, String cloudConfigManifest) {
boolean recreateIfExists = Boolean.parseBoolean(recreate);
boolean cloudConfigIncluded = Boolean.parseBoolean(addCloudConfig);
ClusterSetup clusterSetup = getClusterSetup();
CloudConfig cloudConfig = null;
if (cloudConfigIncluded) {
ZNRecord record;
try {
record = toZNRecord(cloudConfigManifest);
cloudConfig = new CloudConfig.Builder(record).build();
} catch (IOException | HelixException e) {
String errMsg = "Failed to generate a valid CloudConfig from " + cloudConfigManifest;
LOG.error(errMsg, e);
return badRequest(errMsg + " Exception: " + e.getMessage());
}
}
try {
clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig);
} catch (Exception ex) {
LOG.error("Failed to create cluster {}. Exception: {}.", clusterId, ex);
return serverError(ex);
}
return created();
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ClusterAccessor method getCloudConfig.
@ClusterAuth
@ResponseMetered(name = HttpConstants.READ_REQUEST)
@Timed(name = HttpConstants.READ_REQUEST)
@GET
@Path("{clusterId}/cloudconfig")
public Response getCloudConfig(@PathParam("clusterId") String clusterId) {
RealmAwareZkClient zkClient = getRealmAwareZkClient();
if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
return notFound();
}
ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
CloudConfig cloudConfig = configAccessor.getCloudConfig(clusterId);
if (cloudConfig != null) {
return JSONRepresentation(cloudConfig.getRecord());
}
return notFound();
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ClusterAccessor method addCloudConfig.
@ClusterAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@PUT
@Path("{clusterId}/cloudconfig")
public Response addCloudConfig(@PathParam("clusterId") String clusterId, String content) {
RealmAwareZkClient zkClient = getRealmAwareZkClient();
if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
return notFound("Cluster is not properly setup!");
}
HelixAdmin admin = getHelixAdmin();
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
LOG.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a vaild ZNRecord!");
}
try {
CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
admin.addCloudConfig(clusterId, cloudConfig);
} catch (HelixException ex) {
LOG.error("Error in adding a CloudConfig to cluster: " + clusterId, ex);
return badRequest(ex.getMessage());
} catch (Exception ex) {
LOG.error("Cannot add CloudConfig to cluster: " + clusterId, ex);
return serverError(ex);
}
return OK();
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class HelixPropertyFactory method getCloudConfig.
public static CloudConfig getCloudConfig(String zkAddress, String clusterName, RealmAwareZkClient.RealmAwareZkConnectionConfig realmAwareZkConnectionConfig) {
CloudConfig cloudConfig;
RealmAwareZkClient dedicatedZkClient = null;
try {
if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || zkAddress == null) {
// DedicatedZkClient
try {
if (realmAwareZkConnectionConfig == null) {
realmAwareZkConnectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().setRealmMode(RealmAwareZkClient.RealmMode.SINGLE_REALM).setZkRealmShardingKey("/" + clusterName).build();
}
dedicatedZkClient = DedicatedZkClientFactory.getInstance().buildZkClient(realmAwareZkConnectionConfig);
} catch (IOException | InvalidRoutingDataException e) {
throw new HelixException("Not able to connect on multi-ZK mode!", e);
}
} else {
// Use a dedicated ZK client single-ZK mode
HelixZkClient.ZkConnectionConfig connectionConfig = new HelixZkClient.ZkConnectionConfig(zkAddress);
dedicatedZkClient = DedicatedZkClientFactory.getInstance().buildZkClient(connectionConfig);
}
dedicatedZkClient.setZkSerializer(new ZNRecordSerializer());
ConfigAccessor configAccessor = new ConfigAccessor(dedicatedZkClient);
// up yet, constructing a new ZKHelixManager should not throw an exception
try {
cloudConfig = configAccessor.getCloudConfig(clusterName);
if (cloudConfig == null) {
cloudConfig = new CloudConfig();
}
} catch (HelixException e) {
cloudConfig = new CloudConfig();
}
} finally {
// Use a try-finally to make sure zkclient connection is closed properly
if (dedicatedZkClient != null && !dedicatedZkClient.isClosed()) {
dedicatedZkClient.close();
}
}
return cloudConfig;
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestConfigAccessor method testUpdateCloudConfig.
public void testUpdateCloudConfig() throws Exception {
ClusterSetup _clusterSetup = new ClusterSetup(ZK_ADDR);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
CloudConfig.Builder cloudConfigInitBuilder = new CloudConfig.Builder();
cloudConfigInitBuilder.setCloudEnabled(true);
cloudConfigInitBuilder.setCloudID("TestCloudID");
List<String> sourceList = new ArrayList<String>();
sourceList.add("TestURL");
cloudConfigInitBuilder.setCloudInfoSources(sourceList);
cloudConfigInitBuilder.setCloudInfoProcessorName("TestProcessor");
cloudConfigInitBuilder.setCloudProvider(CloudProvider.CUSTOMIZED);
CloudConfig cloudConfigInit = cloudConfigInitBuilder.build();
_clusterSetup.addCluster(clusterName, false, cloudConfigInit);
// Read CloudConfig from Zookeeper and check the content
ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
// Change the processor name and check if processor name has been changed in Zookeeper.
CloudConfig.Builder cloudConfigToUpdateBuilder = new CloudConfig.Builder();
cloudConfigToUpdateBuilder.setCloudInfoProcessorName("TestProcessor2");
CloudConfig cloudConfigToUpdate = cloudConfigToUpdateBuilder.build();
_configAccessor.updateCloudConfig(clusterName, cloudConfigToUpdate);
cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor2");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
}
Aggregations