public void setBucketSize(String resource, int bucketSize) { CurrentState curStateMeta = _curStateMetaMap.get(resource); if (curStateMeta == null) { curStateMeta = new CurrentState(resource); _curStateMetaMap.put(resource, curStateMeta); } curStateMeta.setBucketSize(bucketSize); }
public void setBucketSize(String resource, int bucketSize) { CurrentState curStateMeta = _curStateMetaMap.get(resource); if (curStateMeta == null) { curStateMeta = new CurrentState(resource); _curStateMetaMap.put(resource, curStateMeta); } curStateMeta.setBucketSize(bucketSize); }
/** * Request a state change for a specific task. * * @param accessor connected Helix data accessor * @param instance the instance serving the task * @param sessionId the current session of the instance * @param resource the job name * @param partition the task partition name * @param state the requested state * @return true if the request was persisted, false otherwise */ private static boolean setRequestedState(HelixDataAccessor accessor, String instance, String sessionId, String resource, String partition, TaskPartitionState state) { LOG.debug( String.format("Requesting a state transition to %s for partition %s.", state, partition)); try { PropertyKey.Builder keyBuilder = accessor.keyBuilder(); PropertyKey key = keyBuilder.currentState(instance, sessionId, resource); CurrentState currStateDelta = new CurrentState(resource); currStateDelta.setRequestedState(partition, state.name()); return accessor.updateProperty(key, currStateDelta); } catch (Exception e) { LOG.error(String .format("Error when requesting a state transition to %s for partition %s.", state, partition), e); return false; } } }
/** * Request a state change for a specific task. * * @param accessor connected Helix data accessor * @param instance the instance serving the task * @param sessionId the current session of the instance * @param resource the job name * @param partition the task partition name * @param state the requested state * @return true if the request was persisted, false otherwise */ private static boolean setRequestedState(HelixDataAccessor accessor, String instance, String sessionId, String resource, String partition, TaskPartitionState state) { LOG.debug( String.format("Requesting a state transition to %s for partition %s.", state, partition)); try { PropertyKey.Builder keyBuilder = accessor.keyBuilder(); PropertyKey key = keyBuilder.currentState(instance, sessionId, resource); CurrentState currStateDelta = new CurrentState(resource); currStateDelta.setRequestedState(partition, state.name()); return accessor.updateProperty(key, currStateDelta); } catch (Exception e) { LOG.error(String .format("Error when requesting a state transition to %s for partition %s.", state, partition), e); return false; } } }
@Override public ZNRecord update(ZNRecord currentData) { CurrentState curState = null; if (currentData == null) { curState = new CurrentState(_lastCurState.getId()); // copy all simple fields settings and overwrite session-id to current session curState.getRecord().setSimpleFields(_lastCurState.getRecord().getSimpleFields()); curState.setSessionId(_curSessionId); } else { curState = new CurrentState(currentData); } for (String partitionName : _lastCurState.getPartitionStateMap().keySet()) { // carry-over only when current-state not exist if (curState.getState(partitionName) == null) { curState.setState(partitionName, _initState); } } return curState.getRecord(); }
@Override public ZNRecord update(ZNRecord currentData) { CurrentState curState = null; if (currentData == null) { curState = new CurrentState(_lastCurState.getId()); // copy all simple fields settings and overwrite session-id to current session curState.getRecord().setSimpleFields(_lastCurState.getRecord().getSimpleFields()); curState.setSessionId(_curSessionId); } else { curState = new CurrentState(currentData); } for (String partitionName : _lastCurState.getPartitionStateMap().keySet()) { // carry-over only when current-state not exist if (curState.getState(partitionName) == null) { curState.setState(partitionName, _initState); } } return curState.getRecord(); }
private Map<String, CurrentState> generateCurrentStateMap( Map<String, CurrentStateInfo> currentStateRawData) { Map<String, CurrentState> currentStateMap = new HashMap<String, CurrentState>(); for (String instanceName : currentStateRawData.keySet()) { CurrentStateInfo info = currentStateRawData.get(instanceName); CurrentState currentState = new CurrentState(TEST_RESOURCE); currentState.setSessionId(SESSION_PREFIX + instanceName.split("_")[1]); currentState.setState(PARTITION, info.currentState); currentState.setPreviousState(PARTITION, info.previousState); currentState.setStartTime(PARTITION, info.startTime); currentState.setEndTime(PARTITION, info.endTime); currentStateMap.put(instanceName, currentState); } return currentStateMap; }
metaRecord.setSimpleFields(lastCurState.getRecord().getSimpleFields()); DataUpdater<ZNRecord> metaRecordUpdater = new CurStateCarryOverUpdater(_sessionId, initState, new CurrentState(metaRecord)); boolean success = baseAccessor.update(curStatePath, metaRecordUpdater, AccessOption.PERSISTENT); for (String bucketName : map.keySet()) { paths.add(curStatePath + "/" + bucketName); updaters.add(new CurStateCarryOverUpdater(_sessionId, initState, new CurrentState(map .get(bucketName))));
metaRecord.setSimpleFields(lastCurState.getRecord().getSimpleFields()); DataUpdater<ZNRecord> metaRecordUpdater = new CurStateCarryOverUpdater(_sessionId, initState, new CurrentState(metaRecord)); boolean success = baseAccessor.update(curStatePath, metaRecordUpdater, AccessOption.PERSISTENT); for (String bucketName : map.keySet()) { paths.add(curStatePath + "/" + bucketName); updaters.add(new CurStateCarryOverUpdater(_sessionId, initState, new CurrentState(map .get(bucketName))));
CurrentState currentStateDelta = new CurrentState(resourceName); currentStateDelta.setState(partition, HelixDefinedState.ERROR.toString()); _stateModel.updateState(HelixDefinedState.ERROR.toString());
CurrentState currentStateDelta = new CurrentState(resourceName); currentStateDelta.setState(partition, HelixDefinedState.ERROR.toString()); _stateModel.updateState(HelixDefinedState.ERROR.toString());
private void setCurrentState(String clusterName, String instance, String resourceGroupName, String resourceKey, String sessionId, String state, boolean updateTimestamp) { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient)); Builder keyBuilder = accessor.keyBuilder(); CurrentState curState = new CurrentState(resourceGroupName); curState.setState(resourceKey, state); curState.setSessionId(sessionId); curState.setStateModelDefRef("MasterSlave"); if (updateTimestamp) { curState.setEndTime(resourceKey, System.currentTimeMillis()); } accessor.setProperty(keyBuilder.currentState(instance, sessionId, resourceGroupName), curState); }
CurrentState currentStateDelta = new CurrentState(resourceName); currentStateDelta.setSessionId(sessionId); currentStateDelta.setStateModelDefRef(stateModelName);
CurrentState currentStateDelta = new CurrentState(resourceName); currentStateDelta.setSessionId(sessionId); currentStateDelta.setStateModelDefRef(stateModelName);
CurrentState currentState = new CurrentState(oldResource); currentState.setState("testResourceOld_0", "OFFLINE"); currentState.setState("testResourceOld_1", "SLAVE");
CurrentState currentStateDelta = new CurrentState("TestDB"); currentStateDelta.setState("TestDB_0", "OFFLINE");
CurrentState currentStateDelta = new CurrentState("TestDB"); currentStateDelta.setState("TestDB_0", "OFFLINE");
testListener.Reset(); CurrentState curState = new CurrentState("db-12345"); curState.setSessionId("sessionId"); curState.setStateModelDefRef("StateModelDef");
CurrentState currentStateDelta = new CurrentState("TestDB"); currentStateDelta.setState("TestDB_0", "OFFLINE");
CurrentState stateWithLiveSession = new CurrentState(record1); stateWithLiveSession.setSessionId("session_3"); stateWithLiveSession.setStateModelDefRef("MasterSlave"); stateWithLiveSession.setState("testResourceName_1", "OFFLINE"); ZNRecord record2 = new ZNRecord("testResourceName"); CurrentState stateWithDeadSession = new CurrentState(record2); stateWithDeadSession.setSessionId("session_dead"); stateWithDeadSession.setStateModelDefRef("MasterSlave");