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); } } }
/** * This method retrieves the DocumentWorkerConfiguration or throws an exception. * * @return the DocumentWorkerConfiguration object * @throws WorkerException if there is a problem creating the configuration object */ @Nonnull private static DocumentWorkerConfiguration getConfiguration(final ConfigurationSource configSource) throws WorkerException { try { return configSource.getConfiguration(DocumentWorkerConfiguration.class); } catch (final ConfigurationException ce) { throw new WorkerException("Failed to construct DocumentWorkerConfiguration object", ce); } }
public WorkerFactory getWorkerFactory(ConfigurationSource config, DataStore dataStore, Codec codec) throws WorkerException { { try { Objects.requireNonNull(config); PolicyWorkerConfiguration testConfig = config.getConfiguration(PolicyWorkerConfiguration.class); return new PolicyWorkerFactory(codec, dataStore, testConfig); } catch ( ConfigurationException e ) { throw new WorkerException("Failed to create factory", e); } } }
/** * Instantiates a new DefaultWorkerFactory. * * @param configSource the worker configuration source * @param dataStore the external data store * @param codec the codec used in serialisation * @param configurationClass the worker configuration class * @param taskClass the worker task class * @throws WorkerException if the factory cannot be instantiated */ public AbstractWorkerFactory(final ConfigurationSource configSource, final DataStore dataStore, final Codec codec, final Class<C> configurationClass, final Class<T> taskClass) throws WorkerException { this.codec = Objects.requireNonNull(codec); this.taskClass = Objects.requireNonNull(taskClass); this.dataStore = Objects.requireNonNull(dataStore); try { this.configuration = configSource.getConfiguration(configurationClass); } catch (ConfigurationException e) { throw new WorkerException("Failed to create worker factory", 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); } } }
@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); } } }
@Override public final ManagedDataStore getDataStore(final ConfigurationSource configurationSource) throws DataStoreException { try { StorageServiceDataStoreConfiguration storageServiceDataStoreConfiguration = configurationSource.getConfiguration(StorageServiceDataStoreConfiguration.class); KeycloakClient keycloakClient = storageServiceDataStoreConfiguration.getAuthenticationConfiguration() != null ? new KeycloakClient(storageServiceDataStoreConfiguration.getAuthenticationConfiguration()) : null; return new StorageServiceDataStore(configurationSource.getConfiguration(StorageServiceDataStoreConfiguration.class), keycloakClient); } catch (ConfigurationException e) { throw new DataStoreException("Cannot create object data store", e); } } }
public <TConfig> T createDefault( Class<TConfig> configClass, Function<TConfig, String> queueNameFunc, TestItemProvider itemProvider, WorkerTaskFactory workerTaskFactory, ResultProcessor resultProcessor) throws Exception { WorkerServices workerServices = WorkerServices.getDefault(); ConfigurationSource configurationSource = workerServices.getConfigurationSource(); TConfig workerConfiguration = configurationSource.getConfiguration(configClass); String queueName = queueNameFunc.apply(workerConfiguration); return create(workerServices, queueName, itemProvider, workerTaskFactory, resultProcessor); }
@Override public ServiceScaler getServiceScaler(final ConfigurationSource configurationSource) throws ScalerException { try { MarathonAutoscaleConfiguration config = configurationSource.getConfiguration(MarathonAutoscaleConfiguration.class); URL url = new URL(config.getEndpoint()); Marathon marathon = MarathonClient.getInstance(url.toString()); return new MarathonServiceScaler(marathon, config.getMaximumInstances(), url, new AppInstancePatcher(url.toURI())); } catch (ConfigurationException | MalformedURLException | URISyntaxException e) { throw new ScalerException("Failed to create service scaler", e); } } }
/** * Public method to expose Markup Worker logic to a Document Worker * * @param document Instance of document worker document object * @param hashConfiguration The hash configuration to use when generating document hashes * @param outputFields The list of fields the worker should output * @param isEmail if the document is of email type. * @param emailSplitter python email splitter that is used across multiple threads * @throws InterruptedException throws in cases of a thread being interrupted during processing. * @throws com.hpe.caf.api.ConfigurationException throws when configuration for worker is malformed or missing. */ public void markupDocument(final Document document, final List<HashConfiguration> hashConfiguration, final List<OutputField> outputFields, final boolean isEmail, final EmailSplitter emailSplitter) throws InterruptedException, ConfigurationException { final MarkupWorkerConfiguration config = document.getApplication().getService(ConfigurationSource.class) .getConfiguration(MarkupWorkerConfiguration.class); markupDocument(document, hashConfiguration, outputFields, isEmail, emailSplitter, config); }
@Override public ServiceSource getServiceSource(final ConfigurationSource configurationSource, final ServicePath servicePath) throws ScalerException { try { final MarathonAutoscaleConfiguration config = configurationSource.getConfiguration(MarathonAutoscaleConfiguration.class); final String groupId = getGroupId(config, servicePath); Marathon marathon = MarathonClient.getInstance(config.getEndpoint()); return new MarathonServiceSource(marathon, groupId, new URL(config.getEndpoint())); } catch (ConfigurationException | MalformedURLException e) { throw new ScalerException("Failed to create service source", e); } }
private T create(WorkerServices workerServices, String queueName, TestItemProvider itemProvider, WorkerTaskFactory workerTaskFactory, ResultProcessor resultProcessor) throws Exception { ConfigurationSource configurationSource = workerServices.getConfigurationSource(); RabbitWorkerQueueConfiguration rabbitConfiguration = configurationSource.getConfiguration(RabbitWorkerQueueConfiguration.class); rabbitConfiguration.getRabbitConfiguration().setRabbitHost(SettingsProvider.defaultProvider.getSetting(SettingNames.dockerHostAddress)); rabbitConfiguration.getRabbitConfiguration().setRabbitPort(Integer.parseInt(SettingsProvider.defaultProvider.getSetting(SettingNames.rabbitmqNodePort))); QueueServices queueServices = QueueServicesFactory.create(rabbitConfiguration, queueName, workerServices.getCodec()); boolean debugEnabled = SettingsProvider.defaultProvider.getBooleanSetting(SettingNames.createDebugMessage, false); QueueManager queueManager = new QueueManager(queueServices, workerServices, debugEnabled); boolean stopOnError = SettingsProvider.defaultProvider.getBooleanSetting(SettingNames.stopOnError, false); T controller = createController(workerServices, itemProvider, queueManager, workerTaskFactory, resultProcessor, stopOnError); return controller; }