SanskritNomadServerState implements NomadServerState<NodeContext> { @Override public ChangeRequest<NodeContext> getChangeRequest(UUID changeUuid) throws NomadException { try { String uuidString = changeUuid.toString(); SanskritObject child = getObject(uuidString); if (child == null) { return null; } ChangeRequestState state = ChangeRequestState.valueOf(child.getString(CHANGE_STATE)); long version = child.getLong(CHANGE_VERSION); String changeFormatVersion = child.getString(CHANGE_FORMAT_VERSION); if (changeFormatVersion == null) { changeFormatVersion = Version.V1.getValue(); } NomadChange change = child.getObject(CHANGE_OPERATION, NomadChange.class, changeFormatVersion); String prevChangeUuid = child.getString(PREV_CHANGE_UUID); String expectedHash = child.getString(CHANGE_RESULT_HASH); String creationHost = child.getString(CHANGE_CREATION_HOST); String creationUser = child.getString(CHANGE_CREATION_USER); Instant creationTimestamp = Instant.parse(child.getString(CHANGE_CREATION_TIMESTAMP)); Config config = configStorage.getConfig(version); try { hashComputer.checkHash(config, expectedHash); } catch (NomadException e) { throw new NomadException("Bad hash for change: " + changeUuid + ". " + e.getMessage()); } return new ChangeRequest<>(state, version, prevChangeUuid, change, config.getTopology(), creationHost, creationUser, creationTimestamp); } catch (ConfigStorageException e) { throw new NomadException("Failed to read configuration: " + changeUuid, e); } } SanskritNomadServerState(Sanskrit sanskrit, ConfigStorage configStorage, HashComputer hashComputer); @Override boolean isInitialized(); @Override NomadServerMode getMode(); @Override long getMutativeMessageCount(); @Override String getLastMutationHost(); @Override String getLastMutationUser(); @Override Instant getLastMutationTimestamp(); @Override UUID getLatestChangeUuid(); @Override long getCurrentVersion(); @Override long getHighestVersion(); @Override ChangeRequest<NodeContext> getChangeRequest(UUID changeUuid); @Override NomadStateChange<NodeContext> newStateChange(); @Override void applyStateChange(NomadStateChange<NodeContext> change); @Override Optional<NodeContext> getCurrentCommittedConfig(); @Override void reset();  }
@Test public void getChangeRequest() throws Exception { UUID uuid = UUID.randomUUID(); SettingNomadChange settingNomadChange = SettingNomadChange.set(Applicability.cluster(), OFFHEAP_RESOURCES, "primary-server-resource", "2GB"); MutableSanskritObject changeObject = sanskrit.newMutableSanskritObject(); changeObject.setString("state", "ROLLED_BACK"); changeObject.setLong("version", 1L); changeObject.setExternal("operation", settingNomadChange, Version.CURRENT.getValue()); changeObject.setString("changeResultHash", "1063a7c79380cc1c8372c1f78d1104eefdeed073"); changeObject.setString("creationHost", "host"); changeObject.setString("creationUser", "user"); changeObject.setString("creationTimestamp", now.toString()); changeObject.setString("summary", "description"); when(sanskrit.getObject(uuid.toString())).thenReturn(changeObject); when(configStorage.getConfig(1L)).thenReturn(new Config(topology, Version.CURRENT)); ChangeRequest<NodeContext> changeRequest = state.getChangeRequest(uuid); SettingNomadChange change = (SettingNomadChange) changeRequest.getChange(); assertEquals(ROLLED_BACK, changeRequest.getState()); assertEquals(1L, changeRequest.getVersion()); assertEquals(settingNomadChange, change); assertEquals(topology, changeRequest.getChangeResult()); assertEquals("host", changeRequest.getCreationHost()); assertEquals("user", changeRequest.getCreationUser()); assertEquals(now, changeRequest.getCreationTimestamp()); assertNull(changeRequest.getPrevChangeId()); assertEquals("set offheap-resources.primary-server-resource=2GB", change.getSummary()); }