Search in sources :

Example 11 with ResourceConfig

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();
}
Also used : HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) ResourceConfig(org.apache.helix.model.ResourceConfig) ConfigAccessor(org.apache.helix.ConfigAccessor) ZNRecord(org.apache.helix.ZNRecord) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 12 with ResourceConfig

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);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConfigAccessor(org.apache.helix.ConfigAccessor) ResourceConfig(org.apache.helix.model.ResourceConfig) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) ZNRecord(org.apache.helix.ZNRecord) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with ResourceConfig

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;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixDataAccessor(org.apache.helix.HelixDataAccessor) StringRepresentation(org.restlet.representation.StringRepresentation) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) ResourceConfig(org.apache.helix.model.ResourceConfig) PropertyKey(org.apache.helix.PropertyKey) ZNRecord(org.apache.helix.ZNRecord)

Example 14 with ResourceConfig

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;
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ResourceConfig(org.apache.helix.model.ResourceConfig) HashMap(java.util.HashMap) Map(java.util.Map) JobConfig(org.apache.helix.task.JobConfig)

Aggregations

ResourceConfig (org.apache.helix.model.ResourceConfig)14 List (java.util.List)5 ZNRecord (org.apache.helix.ZNRecord)5 IdealState (org.apache.helix.model.IdealState)5 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 ConfigAccessor (org.apache.helix.ConfigAccessor)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 CrushRebalanceStrategy (org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy)2 MultiRoundCrushRebalanceStrategy (org.apache.helix.controller.rebalancer.strategy.MultiRoundCrushRebalanceStrategy)2 ClusterConfig (org.apache.helix.model.ClusterConfig)2 ExternalView (org.apache.helix.model.ExternalView)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 POST (javax.ws.rs.POST)1 HelixAdmin (org.apache.helix.HelixAdmin)1