use of org.apache.helix.model.ResourceConfig in project helix by apache.
the class ResourceAccessor method updateResourceConfig.
@POST
@Path("{resourceName}/configs")
public Response updateResourceConfig(@PathParam("clusterId") String clusterId, @PathParam("resourceName") String resourceName, String content) {
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
_logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a vaild ZNRecord!");
}
ResourceConfig resourceConfig = new ResourceConfig(record);
ConfigAccessor configAccessor = getConfigAccessor();
try {
configAccessor.updateResourceConfig(clusterId, resourceName, resourceConfig);
} catch (HelixException ex) {
return notFound(ex.getMessage());
} catch (Exception ex) {
_logger.error("Failed to update cluster config, cluster " + clusterId + " new config: " + content + ", Exception: " + ex);
return serverError(ex);
}
return OK();
}
use of org.apache.helix.model.ResourceConfig in project helix by apache.
the class ResourceAccessor method getResource.
@GET
@Path("{resourceName}")
public Response getResource(@PathParam("clusterId") String clusterId, @PathParam("resourceName") String resourceName) {
ConfigAccessor accessor = getConfigAccessor();
HelixAdmin admin = getHelixAdmin();
ResourceConfig resourceConfig = accessor.getResourceConfig(clusterId, resourceName);
IdealState idealState = admin.getResourceIdealState(clusterId, resourceName);
ExternalView externalView = admin.getResourceExternalView(clusterId, resourceName);
Map<String, ZNRecord> resourceMap = new HashMap<>();
if (idealState != null) {
resourceMap.put(ResourceProperties.idealState.name(), idealState.getRecord());
} else {
return notFound();
}
resourceMap.put(ResourceProperties.resourceConfig.name(), null);
resourceMap.put(ResourceProperties.externalView.name(), null);
if (resourceConfig != null) {
resourceMap.put(ResourceProperties.resourceConfig.name(), resourceConfig.getRecord());
}
if (externalView != null) {
resourceMap.put(ResourceProperties.externalView.name(), externalView.getRecord());
}
return JSONRepresentation(resourceMap);
}
use of org.apache.helix.model.ResourceConfig in project helix by apache.
the class JobQueueResource method getHostedEntitiesRepresentation.
StringRepresentation getHostedEntitiesRepresentation(String clusterName, String jobQueueName) throws Exception {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
TaskDriver taskDriver = new TaskDriver(zkClient, clusterName);
// Get job queue config
// TODO: fix this to use workflowConfig.
ResourceConfig jobQueueConfig = accessor.getProperty(keyBuilder.resourceConfig(jobQueueName));
// Get job queue context
WorkflowContext ctx = taskDriver.getWorkflowContext(jobQueueName);
// Create the result
ZNRecord hostedEntitiesRecord = new ZNRecord(jobQueueName);
if (jobQueueConfig != null) {
hostedEntitiesRecord.merge(jobQueueConfig.getRecord());
}
if (ctx != null) {
hostedEntitiesRecord.merge(ctx.getRecord());
}
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.model.ResourceConfig in project helix by apache.
the class TaskDataCache method refresh.
/**
* This refreshes the cluster data by re-fetching the data from zookeeper in an efficient way
*
* @param accessor
*
* @return
*/
public synchronized boolean refresh(HelixDataAccessor accessor, Map<String, ResourceConfig> resourceConfigMap) {
refreshJobContexts(accessor);
// update workflow and job configs.
_workflowConfigMap.clear();
_jobConfigMap.clear();
for (Map.Entry<String, ResourceConfig> entry : resourceConfigMap.entrySet()) {
if (entry.getValue().getRecord().getSimpleFields().containsKey(WorkflowConfig.WorkflowConfigProperty.Dag.name())) {
_workflowConfigMap.put(entry.getKey(), new WorkflowConfig(entry.getValue()));
} else if (entry.getValue().getRecord().getSimpleFields().containsKey(WorkflowConfig.WorkflowConfigProperty.WorkflowID.name())) {
_jobConfigMap.put(entry.getKey(), new JobConfig(entry.getValue()));
}
}
return true;
}
Aggregations