org.apache.helix.PropertyKey Java Examples
The following examples show how to use
org.apache.helix.PropertyKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstanceResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getInstanceRepresentation() throws JsonGenerationException, JsonMappingException, IOException { String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME); String instanceName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.INSTANCE_NAME); Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT); String instanceCfgStr = ResourceUtil.readZkAsBytes(zkclient, keyBuilder.instanceConfig(instanceName)); StringRepresentation representation = new StringRepresentation(instanceCfgStr, MediaType.APPLICATION_JSON); return representation; }
Example #2
Source File: ErrorResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getInstanceErrorsRepresentation(String clusterName, String instanceName, String resourceGroup) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); Builder keyBuilder = new PropertyKey.Builder(clusterName); String message = ClusterRepresentationUtil.getInstancePropertiesAsString(zkClient, clusterName, keyBuilder.stateTransitionErrors(instanceName, instanceSessionId, resourceGroup), // instanceSessionId // + "__" // + resourceGroup, MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example #3
Source File: RebalanceScheduler.java From helix with Apache License 2.0 | 6 votes |
/** * This function is deprecated. Please use RebalanceUtil.scheduleInstantPipeline method instead. * Trigger the controller to perform rebalance for a given resource. * @param accessor Helix data accessor * @param resource the name of the resource changed to triggering the execution */ @Deprecated public static void invokeRebalanceForResourceConfig(HelixDataAccessor accessor, String resource) { LOG.info("invoke rebalance for " + resource); PropertyKey key = accessor.keyBuilder().resourceConfig(resource); ResourceConfig cfg = accessor.getProperty(key); if (cfg != null) { // Here it uses the updateProperty function with no-op DataUpdater. Otherwise, it will use default // ZNRecordUpdater which will duplicate elements for listFields. if (!accessor.updateProperty(key, znRecord -> znRecord, cfg)) { LOG.warn("Failed to invoke rebalance on resource config {}", resource); } } else { LOG.warn("Can't find resource config for {}", resource); } }
Example #4
Source File: ClusterAccessor.java From helix with Apache License 2.0 | 6 votes |
@DELETE @Path("{clusterId}/statemodeldefs/{statemodel}") public Response removeClusterStateModelDefinition(@PathParam("clusterId") String clusterId, @PathParam("statemodel") String statemodel) { //Shall we validate the statemodel string not having special character such as ../ etc? if (!StringUtils.isAlphanumeric(statemodel)) { return badRequest("Invalid statemodel name!"); } HelixDataAccessor dataAccessor = getDataAccssor(clusterId); PropertyKey key = dataAccessor.keyBuilder().stateModelDef(statemodel); boolean retcode = true; try { retcode = dataAccessor.removeProperty(key); } catch (Exception e) { LOG.error("Failed to remove StateModelDefinition key: {}. Exception: {}.", key, e); retcode = false; } if (!retcode) { return badRequest("Failed to remove!"); } return OK(); }
Example #5
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Override public void removeTypeFromCustomizedStateConfig(String clusterName, String type) { logger.info("Remove type {} to CustomizedStateConfig of cluster {}", type, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder( _configAccessor.getCustomizedStateConfig(clusterName)); if (!builder.getAggregationEnabledTypes().contains(type)) { throw new HelixException("Type " + type + " is missing from the CustomizedStateConfig of cluster " + clusterName); } builder.removeAggregationEnabledType(type); CustomizedStateConfig customizedStateConfigFromBuilder = builder.build(); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.customizedStateConfig(), customizedStateConfigFromBuilder); }
Example #6
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Override public void addTypeToCustomizedStateConfig(String clusterName, String type) { logger.info("Add type {} to CustomizedStateConfig of cluster {}", type, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(); builder.addAggregationEnabledType(type); CustomizedStateConfig customizedStateConfigFromBuilder = builder.build(); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); accessor.updateProperty(keyBuilder.customizedStateConfig(), customizedStateConfigFromBuilder); }
Example #7
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Override public void addCustomizedStateConfig(String clusterName, CustomizedStateConfig customizedStateConfig) { logger.info( "Add CustomizedStateConfig to cluster {}, CustomizedStateConfig is {}", clusterName, customizedStateConfig.toString()); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(customizedStateConfig); CustomizedStateConfig customizedStateConfigFromBuilder = builder.build(); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.customizedStateConfig(), customizedStateConfigFromBuilder); }
Example #8
Source File: TestStateTransitionThrottle.java From helix with Apache License 2.0 | 6 votes |
private void setupCluster(String clusterName, ZKHelixDataAccessor accessor) throws Exception { String resourceNamePrefix = "TestDB"; TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port "localhost", // participant name prefix resourceNamePrefix, // resource name prefix 1, // resources 15, // partitions per resource participantCount, // number of nodes 3, // replicas "MasterSlave", IdealState.RebalanceMode.FULL_AUTO, true); // do rebalance PropertyKey.Builder keyBuilder = accessor.keyBuilder(); ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig()); clusterConfig.setResourcePriorityField("Name"); List<StateTransitionThrottleConfig> throttleConfigs = new ArrayList<>(); throttleConfigs.add( new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100)); throttleConfigs.add(new StateTransitionThrottleConfig( StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100)); clusterConfig.setStateTransitionThrottleConfigs(throttleConfigs); accessor.setProperty(keyBuilder.clusterConfig(), clusterConfig); }
Example #9
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Override public void addInstanceTag(String clusterName, String instanceName, String tag) { logger .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException( "cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.addTag(tag); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
Example #10
Source File: ZKHelixDataAccessor.java From helix with Apache License 2.0 | 6 votes |
@Override public <T extends HelixProperty> boolean[] createChildren(List<PropertyKey> keys, List<T> children) { // TODO: add validation int options = -1; List<String> paths = new ArrayList<String>(); List<ZNRecord> records = new ArrayList<ZNRecord>(); for (int i = 0; i < keys.size(); i++) { PropertyKey key = keys.get(i); PropertyType type = key.getType(); String path = key.getPath(); paths.add(path); HelixProperty value = children.get(i); records.add(value.getRecord()); options = constructOptions(type); } return _baseDataAccessor.createChildren(paths, records, options); }
Example #11
Source File: TestClusterService.java From helix with Apache License 2.0 | 6 votes |
@Test public void testGetClusterTopology_whenMultiZones() { InstanceConfig instanceConfig1 = new InstanceConfig("instance0"); instanceConfig1.setDomain("helixZoneId=zone0"); InstanceConfig instanceConfig2 = new InstanceConfig("instance1"); instanceConfig2.setDomain("helixZoneId=zone1"); List<HelixProperty> instanceConfigs = (List) ImmutableList.of(instanceConfig1, instanceConfig2); Mock mock = new Mock(); when(mock.dataAccessor.keyBuilder()).thenReturn(new PropertyKey.Builder(TEST_CLUSTER)); when(mock.dataAccessor.getChildValues(any(PropertyKey.class), anyBoolean())).thenReturn(instanceConfigs); ClusterTopology clusterTopology = mock.clusterService.getClusterTopology(TEST_CLUSTER); Assert.assertEquals(clusterTopology.getZones().size(), 2); Assert.assertEquals(clusterTopology.getClusterId(), TEST_CLUSTER); }
Example #12
Source File: DistributedLeaderElection.java From helix with Apache License 2.0 | 6 votes |
private void acquireLeadership(final HelixManager manager, ControllerManagerHelper controllerHelper) { HelixDataAccessor accessor = manager.getHelixDataAccessor(); PropertyKey leaderNodePropertyKey = accessor.keyBuilder().controllerLeader(); LOG.info(manager.getInstanceName() + " tries to acquire leadership for cluster: " + manager .getClusterName()); // Try to acquire leader and init the manager in any case. // Even when a leader node already exists, the election process shall still try to init the manager // in case it is the current leader. do { // Due to the possible carried over ZK events from the previous ZK session, the following // initialization might be triggered multiple times. So the operation must be idempotent. long start = System.currentTimeMillis(); if (tryCreateController(manager)) { manager.getHelixDataAccessor().getBaseDataAccessor().reset(); controllerHelper.addListenersToController(_controller); controllerHelper.startControllerTimerTasks(); LOG.info("{} with session {} acquired leadership for cluster: {}, took: {}ms", manager.getInstanceName(), manager.getSessionId(), manager.getClusterName(), System.currentTimeMillis() - start); } } while (accessor.getProperty(leaderNodePropertyKey) == null); }
Example #13
Source File: CustomizedViewCache.java From helix with Apache License 2.0 | 6 votes |
protected CustomizedViewCache(String clusterName, PropertyType propertyType, String customizedStateType) { super(createDefaultControlContextProvider(clusterName)); _clusterName = clusterName; _propertyType = propertyType; _customizedStateType = customizedStateType; _customizedViewCache = new PropertyCache<>(AbstractDataCache.createDefaultControlContextProvider(clusterName), "CustomizedView", new PropertyCache.PropertyCacheKeyFuncs<CustomizedView>() { @Override public PropertyKey getRootKey(HelixDataAccessor accessor) { return accessor.keyBuilder().customizedView(_customizedStateType); } @Override public PropertyKey getObjPropertyKey(HelixDataAccessor accessor, String objName) { return accessor.keyBuilder().customizedView(_customizedStateType, objName); } @Override public String getObjName(CustomizedView obj) { return obj.getResourceName(); } }, true); }
Example #14
Source File: TestClusterAccessor.java From helix with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testCreateDeleteCluster") public void testEnableDisableCluster() { System.out.println("Start test :" + TestHelper.getTestMethodName()); // disable a cluster. String cluster = _clusters.iterator().next(); _auditLogger.clearupLogs(); post("clusters/" + cluster, ImmutableMap.of("command", "disable"), Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); PropertyKey.Builder keyBuilder = new PropertyKey.Builder(cluster); // verify the cluster is paused. Assert.assertTrue(_baseAccessor.exists(keyBuilder.pause().getPath(), 0)); // enable a cluster. post("clusters/" + cluster, ImmutableMap.of("command", "enable"), Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); // verify the cluster is paused. Assert.assertFalse(_baseAccessor.exists(keyBuilder.pause().getPath(), 0)); Assert.assertEquals(_auditLogger.getAuditLogs().size(), 2); System.out.println("End test :" + TestHelper.getTestMethodName()); }
Example #15
Source File: LeadControllerUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Gets Helix leader in the cluster. Null if there is no leader. * @param helixManager helix manager * @return instance id of Helix cluster leader, e.g. localhost_9000. */ public static String getHelixClusterLeader(HelixManager helixManager) { HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor(); PropertyKey propertyKey = helixDataAccessor.keyBuilder().controllerLeader(); LiveInstance liveInstance = helixDataAccessor.getProperty(propertyKey); if (liveInstance == null) { LOGGER.warn("Helix leader ZNode is missing"); return null; } String helixLeaderInstanceId = liveInstance.getInstanceName(); String helixVersion = liveInstance.getHelixVersion(); long modifiedTime = liveInstance.getModifiedTime(); LOGGER.info("Getting Helix leader: {}, Helix version: {}, mtime: {}", helixLeaderInstanceId, helixVersion, modifiedTime); return helixLeaderInstanceId; }
Example #16
Source File: CustomizedStateProvider.java From helix with Apache License 2.0 | 5 votes |
/** * Get the customized state for a specified resource and a specified partition */ public Map<String, String> getPerPartitionCustomizedState(String customizedStateName, String resourceName, String partitionName) { PropertyKey.Builder keyBuilder = _helixDataAccessor.keyBuilder(); Map<String, Map<String, String>> mapView = _helixDataAccessor .getProperty(keyBuilder.customizedState(_instanceName, customizedStateName, resourceName)) .getRecord().getMapFields(); return mapView.get(partitionName); }
Example #17
Source File: GenericHelixController.java From helix with Apache License 2.0 | 5 votes |
@Override public void run() { try { if (_shouldRefreshCacheOption.orElse( _clusterEventType.equals(ClusterEventType.PeriodicalRebalance) || _clusterEventType .equals(ClusterEventType.OnDemandRebalance))) { requestDataProvidersFullRefresh(); HelixDataAccessor accessor = _manager.getHelixDataAccessor(); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); List<LiveInstance> liveInstances = accessor.getChildValues(keyBuilder.liveInstances(), true); if (liveInstances != null && !liveInstances.isEmpty()) { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); synchronized (_manager) { checkLiveInstancesObservation(liveInstances, changeContext); } } } forceRebalance(_manager, _clusterEventType); } catch (Throwable ex) { logger.error("Time task failed. Rebalance task type: " + _clusterEventType + ", cluster: " + _clusterName, ex); } }
Example #18
Source File: ExternalViewCache.java From helix with Apache License 2.0 | 5 votes |
private PropertyKey externalViewsKey(PropertyKey.Builder keyBuilder) { PropertyKey evPropertyKey; if (_type.equals(PropertyType.EXTERNALVIEW)) { evPropertyKey = keyBuilder.externalViews(); } else if (_type.equals(PropertyType.TARGETEXTERNALVIEW)) { evPropertyKey = keyBuilder.targetExternalViews(); } else { throw new HelixException( "Failed to refresh ExternalViewCache, Wrong property type " + _type + "!"); } return evPropertyKey; }
Example #19
Source File: TestNoThrottleDisabledPartitions.java From helix with Apache License 2.0 | 5 votes |
/** * Ensure that there are 2 messages for a given Participant. * @param participant * @return */ private boolean verifyTwoMessages(final MockParticipantManager participant) { PropertyKey key = _accessor.keyBuilder().messages(participant.getInstanceName()); List<String> messageNames = _accessor.getChildNames(key); if (messageNames != null) { return messageNames.size() == 2; } return false; }
Example #20
Source File: TestNamespacedAPIAccess.java From helix with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testDefaultNamespaceDisabled") public void testNamespacedCRUD() throws IOException { String testClusterName = "testClusterForNamespacedCRUD"; // Create cluster in test namespace and verify it's only appears in test namespace put(String.format("/namespaces/%s/clusters/%s", TEST_NAMESPACE, testClusterName), null, Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.CREATED.getStatusCode()); get(String.format("/namespaces/%s/clusters/%s", TEST_NAMESPACE, testClusterName), null, Response.Status.OK.getStatusCode(), false); get(String.format("/clusters/%s", testClusterName), null, Response.Status.NOT_FOUND.getStatusCode(), false); // Create a cluster with same name in a different namespace put(String.format("/clusters/%s", testClusterName), null, Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.CREATED.getStatusCode()); get(String.format("/clusters/%s", testClusterName), null, Response.Status.OK.getStatusCode(), false); // Modify cluster in default namespace post(String.format("/clusters/%s", testClusterName), ImmutableMap.of("command", "disable"), Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); // Verify the cluster in default namespace is modified, while the one in test namespace is not. PropertyKey.Builder keyBuilder = new PropertyKey.Builder(testClusterName); Assert.assertTrue(_baseAccessor.exists(keyBuilder.pause().getPath(), 0)); Assert.assertFalse(_baseAccessorTestNS.exists(keyBuilder.pause().getPath(), 0)); // Verify that deleting cluster in one namespace will not affect the other delete(String.format("/namespaces/%s/clusters/%s", TEST_NAMESPACE, testClusterName), Response.Status.OK.getStatusCode()); get(String.format("/namespaces/%s/clusters/%s", TEST_NAMESPACE, testClusterName), null, Response.Status.NOT_FOUND.getStatusCode(), false); get(String.format("/clusters/%s", testClusterName), null, Response.Status.OK.getStatusCode(), false); // Remove empty test clusters. Otherwise, it could fail ClusterAccessor tests delete(String.format("/clusters/%s", testClusterName), Response.Status.OK.getStatusCode()); }
Example #21
Source File: ZKHelixDataAccessor.java From helix with Apache License 2.0 | 5 votes |
public ZKHelixDataAccessor(String clusterName, InstanceType instanceType, BaseDataAccessor<ZNRecord> baseDataAccessor) { _clusterName = clusterName; _instanceType = instanceType; _baseDataAccessor = baseDataAccessor; _propertyKeyBuilder = new PropertyKey.Builder(_clusterName); }
Example #22
Source File: TaskUtil.java From helix with Apache License 2.0 | 5 votes |
/** * Cleans up IdealState and external view associated with a job/workflow resource. */ private static boolean cleanupIdealStateExtView(final HelixDataAccessor accessor, String workflowJobResource) { boolean success = true; PropertyKey isKey = accessor.keyBuilder().idealStates(workflowJobResource); if (accessor.getPropertyStat(isKey) != null) { if (!accessor.removeProperty(isKey)) { LOG.warn(String.format( "Error occurred while trying to remove IdealState for %s. Failed to remove node %s.", workflowJobResource, isKey)); success = false; } } // Delete external view PropertyKey evKey = accessor.keyBuilder().externalView(workflowJobResource); if (accessor.getPropertyStat(evKey) != null) { if (!accessor.removeProperty(evKey)) { LOG.warn(String.format( "Error occurred while trying to remove ExternalView of resource %s. Failed to remove node %s.", workflowJobResource, evKey)); success = false; } } return success; }
Example #23
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Override public void dropResource(String clusterName, String resourceName) { logger.info("Drop resource {} from cluster {}", resourceName, clusterName); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); accessor.removeProperty(keyBuilder.idealStates(resourceName)); accessor.removeProperty(keyBuilder.resourceConfig(resourceName)); }
Example #24
Source File: ResourceGroupsResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getHostedEntitiesRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException { // Get all resources ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT); PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName); Map<String, String> idealStateMap = ResourceUtil.readZkChildrenAsBytesMap(zkclient, keyBuilder.idealStates()); // Create the result ZNRecord hostedEntitiesRecord = new ZNRecord("ResourceGroups"); // Figure out which tags are present on which resources Map<String, String> tagMap = Maps.newHashMap(); for (String resourceName : idealStateMap.keySet()) { String idealStateStr = idealStateMap.get(resourceName); String tag = ResourceUtil.extractSimpleFieldFromZNRecord(idealStateStr, IdealState.IdealStateProperty.INSTANCE_GROUP_TAG.toString()); if (tag != null) { tagMap.put(resourceName, tag); } } // Populate the result List<String> allResources = Lists.newArrayList(idealStateMap.keySet()); hostedEntitiesRecord.setListField("ResourceGroups", allResources); if (!tagMap.isEmpty()) { hostedEntitiesRecord.setMapField("ResourceTags", tagMap); } StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON); return representation; }
Example #25
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Override public ClusterConstraints getConstraints(String clusterName, ConstraintType constraintType) { HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName); return accessor.getProperty(keyBuilder.constraint(constraintType.toString())); }
Example #26
Source File: TestAbnormalStatesResolver.java From helix with Apache License 2.0 | 5 votes |
private long getTopStateUpdateTime(ExternalView ev, String partition, String state) { String topStateHost = ev.getStateMap(partition).entrySet().stream() .filter(entry -> entry.getValue().equals(state)).findFirst().get().getKey(); MockParticipantManager participant = Arrays.stream(_participants) .filter(instance -> instance.getInstanceName().equals(topStateHost)).findFirst().get(); HelixDataAccessor accessor = _controller.getHelixDataAccessor(); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); CurrentState currentState = accessor.getProperty(keyBuilder .currentState(participant.getInstanceName(), participant.getSessionId(), ev.getResourceName())); return currentState.getEndTime(partition); }
Example #27
Source File: ResourceGroupResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getIdealStateRepresentation(String clusterName, String resourceName) throws JsonGenerationException, JsonMappingException, IOException { Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT); String idealStateStr = ResourceUtil.readZkAsBytes(zkclient, keyBuilder.idealStates(resourceName)); StringRepresentation representation = new StringRepresentation(idealStateStr, MediaType.APPLICATION_JSON); return representation; }
Example #28
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Override public StateModelDefinition getStateModelDef(String clusterName, String stateModelName) { HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); return accessor.getProperty(keyBuilder.stateModelDef(stateModelName)); }
Example #29
Source File: ZKHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Override public void removeCloudConfig(String clusterName) { logger.info("Remove Cloud Config for cluster {}.", clusterName); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); accessor.removeProperty(keyBuilder.cloudConfig()); }
Example #30
Source File: JobQueueResource.java From helix with Apache License 2.0 | 5 votes |
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; }