@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { doConfigure(profile); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getPrefix()), e); } }
@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { doConfigure(profile); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getPrefix()), e); } }
private void configureResourceId(ServiceProfile<?> profile) { assert profile != null; String override = profile.getConfiguration(ExecutionScriptHandler.KEY_RESOURCE, false, true); if (override == null) { LOG.debug("resourceId is not override in {}", profile.getPrefix()); resourceId = ExecutionScriptHandler.DEFAULT_RESOURCE_ID; } else { LOG.debug("resourceId is overriden in {}: {}", profile.getPrefix(), override); resourceId = override; } }
private void checkPrefix(ServiceProfile<?> profile, String prefix) { assert profile != null; assert prefix != null; if (profile.getPrefix().equals(prefix) == false) { throw new IllegalArgumentException(MessageFormat.format( "Profile \"{1}\" is invalid, this must be \"{0}\" ({2})", prefix, profile.getPrefix(), profile.getServiceClass().getName())); } }
@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { configureScope(profile); doConfigure(profile); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getPrefix()), e); } }
@Override public void doConfigure(ServiceProfile<?> profile) throws InterruptedException, IOException { LOG.debug("Configuring file sessions: {}", profile.getPrefix()); directory = prepareDirectory(profile); LOG.debug("Configured file sessions: {}", directory); }
private void configureStepUnit(ServiceProfile<?> profile) throws IOException { assert profile != null; String stepUnitString = profile.getConfiguration(KEY_STEP_UNIT, false, true); if (stepUnitString == null) { LOG.debug("{} is not defined in {}", KEY_STEP_UNIT, profile.getPrefix()); } else { try { stepUnit = Double.parseDouble(stepUnitString); } catch (NumberFormatException e) { throw new IOException(MessageFormat.format( "{0}.{1} must be a number: {2}", profile.getPrefix(), KEY_STEP_UNIT, stepUnitString)); } } }
private boolean extractBoolean(ServiceProfile<?> profile, String key, boolean defaultValue) throws IOException { assert profile != null; assert key != null; String string = profile.getConfiguration(key, false, true); if (string == null) { return defaultValue; } string = string.trim(); if (string.isEmpty()) { return defaultValue; } try { return Boolean.parseBoolean(string); } catch (RuntimeException e) { throw new IOException(MessageFormat.format( "Failed to resolve boolean value ({0}={1})", profile.getPrefix() + '.' + key, string), e); } }
private File getConfDirectory(ServiceProfile<?> profile) { assert profile != null; String value = profile.getConfiguration(KEY_DIRECTORY, true, true); File dir = new File(value); if (dir.exists() == false) { YSLOG.info("I00001", profile.getPrefix(), KEY_DIRECTORY, value); } return dir; }
@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { this.prefix = profile.getPrefix(); try { configureResourceId(profile); Map<String, String> desiredProperties = getDesiredProperties(profile); Map<String, String> desiredEnvironmentVariables = getDesiredEnvironmentVariables(profile); this.properties = Collections.unmodifiableMap(desiredProperties); this.environmentVariables = Collections.unmodifiableMap(desiredEnvironmentVariables); doConfigure(profile, desiredProperties, desiredEnvironmentVariables); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getPrefix()), e); } }
@Override protected void configureExtension(ServiceProfile<?> profile) throws InterruptedException, IOException { try { this.executor = JschProcessExecutor.extract( profile.getPrefix(), profile.getConfiguration(), profile.getContext().getContextParameters()); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure SSH: {0}", profile.getPrefix()), e); } catch (JSchException e) { throw new IOException(MessageFormat.format( "Failed to configure SSH: {0}", profile.getPrefix()), e); } }
@Override protected void configureExtension(ServiceProfile<?> profile) throws InterruptedException, IOException { try { this.executor = JschProcessExecutor.extract( profile.getPrefix(), profile.getConfiguration(), profile.getContext().getContextParameters()); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure SSH: {0}", profile.getPrefix()), e); } catch (JSchException e) { throw new IOException(MessageFormat.format( "Failed to configure SSH: {0}", profile.getPrefix()), e); } }
private static long extractLong( ServiceProfile<?> profile, Map<String, String> conf, String key, long defaultValue) { assert profile != null; assert conf != null; assert key != null; String value = profile.normalize(key, conf.remove(key), false, true); if (value == null) { return defaultValue; } try { return Long.parseLong(value); } catch (RuntimeException e) { throw new IllegalArgumentException(MessageFormat.format( "{0}.{1} must be an integer ({2})", profile.getPrefix(), key, value)); } }
private void checkCleanupConfigurations(ServiceProfile<?> profile) throws IOException { assert profile != null; String workingDirectory = profile.getConfiguration().get(KEY_WORKING_DIRECTORY); if (workingDirectory != null) { YSLOG.warn("W10001", profile.getPrefix(), KEY_WORKING_DIRECTORY, KEY_CLEANUP); } List<String> cleanupPrefix = extractCommand(profile, ProcessUtil.PREFIX_CLEANUP); if (cleanupPrefix.isEmpty() == false) { YSLOG.warn("W10001", profile.getPrefix(), ProcessUtil.PREFIX_CLEANUP + "*", KEY_CLEANUP); } }
@Override protected void doConfigure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { this.executor = ParallelJobExecutor.extract( profile.getPrefix(), profile.getConfiguration(), profile.getContext().getContextParameters()); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure job scheduler: {0}", profile.getPrefix()), e); } }
@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { configureVersion(profile); doConfigure(profile); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getServiceClass().getName()), e); } }
private List<String> extractCommand(ServiceProfile<?> profile, String prefix) throws IOException { try { return ProcessUtil.extractCommandLineTokens( prefix, profile.getConfiguration(), profile.getContext().getContextParameters()); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to resolve command line tokens ({0})", profile.getPrefix() + '.' + prefix + '*'), e); } }
private List<String> extractCommand( ServiceProfile<?> profile, String prefix) throws IOException { try { return ProcessUtil.extractCommandLineTokens( prefix, profile.getConfiguration(), profile.getContext().getContextParameters()); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to resolve command line tokens ({0})", profile.getPrefix() + '.' + prefix + '*'), e); } }
private void configureScope(ServiceProfile<?> profile) throws IOException { assert profile != null; String scopeSymbol = profile.getConfiguration(KEY_SCOPE, false, true); if (scopeSymbol == null) { scope = ExecutionLock.Scope.getDefault(); LOG.debug("Lock scope is not defined, use default: {}", scope.getSymbol()); } else { scope = ExecutionLock.Scope.findFromSymbol(scopeSymbol); if (scope == null) { throw new IOException(MessageFormat.format( "Unknown lock scope in \"{0}.{1}\": {2}", profile.getPrefix(), KEY_SCOPE, scopeSymbol)); } } }
private String getCommand( ExecutionContext context, String command, HadoopScript script) throws IOException, InterruptedException { assert command != null; Map<String, String> variables; if (script != null) { variables = buildEnvironmentVariables(context, script); } else { variables = getEnvironmentVariables(context, null); } String home = variables.get(ExecutionScript.ENV_ASAKUSA_HOME); if (home == null) { throw new IOException(MessageFormat.format( "Asakusa installation path is not known: {0}", currentProfile.getPrefix() + '.' + KEY_ENV_PREFIX + ExecutionScript.ENV_ASAKUSA_HOME)); } if (home.endsWith(getPathSegmentSeparator())) { return home + command; } else { return home + getPathSegmentSeparator() + command; } }