default <T> T deserialise(byte[] data, Class<T> clazz) throws CodecException { return deserialise(data, clazz, DecodeMethod.getDefault()); }
private String getConfigPath(final BootstrapConfiguration bootstrap) throws ConfigurationException { String ret; if (bootstrap.isConfigurationPresent(CONFIG_PATH)) { ret = bootstrap.getConfiguration(CONFIG_PATH); } else if (bootstrap.isConfigurationPresent(OLD_CONFIG_PATH)) { ret = bootstrap.getConfiguration(OLD_CONFIG_PATH); } else { throw new ConfigurationException("Configuration parameter " + CONFIG_PATH + " not present"); } return ret; } }
/** * Generate a context from provided policy worker task data that can be used by this converter to reconstruct the * policy worker task when converting a result returned by another worker. * @param taskData Policy worker task data representing current processing progress. * @param codec Codec to use in serializing context. * @return Serialized context that converter will be able to rebuild the provided task data state from. * @throws CodecException If an exception occurs serializing the constructed context. */ default byte[] generatePolicyWorkerContext(final TaskData taskData, final Codec codec) throws CodecException { return codec.serialise(taskData); }
@Override public <T> T deserialiseData(Class<T> clazz, DecodeMethod decodeMethod) throws CodecException { final byte[] data = workerTask.getData(); return codec.deserialise(data, clazz, decodeMethod); }
private static <T extends Object> T getConfiguration(final ConfigurationSource configSource, final Class<T> type) throws ScalerException { try { return configSource.getConfiguration(type); } catch (final ConfigurationException ex) { throw new ScalerException("Unable to get configuration.", ex); } } }
@Override public <T> T getObject(final String ref, final Class<T> clazz) throws DataSourceException { try (QuietResource<InputStream> qr = new QuietResource<>(getStream(ref))) { try { return codec.deserialise(qr.get(), clazz); } catch (CodecException e) { throw new DataSourceException("Could not deserialise stream", e); } } }
public <T> byte[] serialiseResult(final T result) { try { return codec.serialise(result); } catch (final CodecException e) { throw new TaskFailedException("Failed to serialise result", e); } }
@Override public final ManagedDataStore getDataStore(final ConfigurationSource configurationSource) throws DataStoreException { try { return new FileSystemDataStore(configurationSource.getConfiguration(FileSystemDataStoreConfiguration.class)); } catch (ConfigurationException e) { throw new DataStoreException("Cannot create data store", e); } } }
/** * Takes in a context previously generated by a converter and returns the policy worker task data it represents. * @param context Representation of the policy worker state that may be used in constructing a TaskData. * @param taskData The task data intended for this converter to convert which may contain information for use in constructing * the policy worker task data. * @param codec Codec to use in deserializing context. * @return The constructed policy worker task data from the parameters provided. * @throws CodecException If an exception occurs during operations using provided codec. */ default TaskData convertPolicyWorkerContext(final byte[] context, final byte[] taskData, final Codec codec) throws CodecException { return codec.deserialise(context, TaskData.class); }
public static WorkerServices create() throws ModuleLoaderException, CipherException, ConfigurationException, DataStoreException { Codec codec = ModuleLoader.getService(Codec.class); ConfigurationDecoderProvider decoderProvider = ModuleLoader.getService(ConfigurationDecoderProvider.class, CafConfigurationDecoderProvider.class); Decoder decoder = decoderProvider.getDecoder(bootstrapConfiguration, codec); Cipher cipher = ModuleLoader.getService(CipherProvider.class, NullCipherProvider.class).getCipher(bootstrapConfiguration); ServicePath path = bootstrapConfiguration.getServicePath(); ConfigurationSource configurationSource = ModuleLoader.getService(ConfigurationSourceProvider.class).getConfigurationSource(bootstrapConfiguration, cipher, path, decoder); DataStore dataStore = ModuleLoader.getService(DataStoreProvider.class).getDataStore(configurationSource); return new WorkerServices(bootstrapConfiguration, codec, cipher, configurationSource, dataStore); } }
@Override protected Result check() throws Exception { HealthResult result = reporter.healthCheck(); String message = result.getMessage(); if (result.getStatus() == HealthStatus.HEALTHY) { return message == null ? Result.healthy() : Result.healthy(message); } else { return Result.unhealthy(message); } } }
@Override public void reportUnhealthy(final String message) { // If there has already been an unhealthy report then discard this new one (i.e. we assume it is better to return the original) if (healthResult != null) { return; } // Construct the new health result healthResult = new HealthResult(HealthStatus.UNHEALTHY, message); }
@Configuration public class WorkerConfiguration { private String workerName; private String workerVersion; public String getWorkerName() { return workerName; } public String getWorkerVersion() { return workerVersion; } public void setWorkerName(String workerName) { this.workerName = workerName; } public void setWorkerVersion(String workerVersion) { this.workerVersion = workerVersion; } }
@Override public void initialize(final ContainsStringKeys containsStringKeys) { requiredKeys = containsStringKeys.keys(); }
@Override public void run() { core.shutdown(); config.shutdown(); scheduler.shutdownNow(); } });
@Override public <T> T deserialiseData(Class<T> clazz) throws CodecException { final byte[] data = workerTask.getData(); return codec.deserialise(data, clazz); }
@Override public AlertDispatcher getAlertDispatcher(final ConfigurationSource configs) throws ScalerException { try { return new EmailDispatcher(configs.getConfiguration(EmailDispatcherConfiguration.class)); } catch (final ConfigurationException ex) { throw new ScalerException("Unable to create email dispatcher, cannot find email dispatcher configuration.", ex); } } }
/** * Deserialise the given data into the specified class using the default decode method. * * @param stream the serialised data as a stream * @param clazz the class the serialised data represents * @param <T> the class the serialised data represents * @return an instance of the class specified represented by the data * @throws CodecException if the data could not be deserialised */ @Override default <T> T deserialise(InputStream stream, Class<T> clazz) throws CodecException { return deserialise(stream, clazz, DecodeMethod.getDefault()); }
public void publishDebugOutput(TaskMessage message) throws CodecException, IOException { byte[] data = workerServices.getCodec().serialise(message); debugConChan.basicPublish("", debugOutputQueueName, MessageProperties.TEXT_PLAIN, data); }
@Override protected HealthCheck.Result check() throws Exception { HealthResult result = reporter.healthCheck(); String message = result.getMessage(); if ( result.getStatus() == HealthStatus.HEALTHY ) { return message == null ? HealthCheck.Result.healthy() : HealthCheck.Result.healthy(message); } else { return HealthCheck.Result.unhealthy(message); } } }