Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.whirr.service;
 
 import java.io.File;
 import java.net.URI;
 
This is a utility class to make it easier to implement ClusterActionHandler. For each 'before' and 'after' action type there is a corresponding method that implementations may override.
 
 public abstract class ClusterActionHandlerSupport extends ClusterActionHandler {
 
   private static final Logger LOG =
     LoggerFactory.getLogger(ClusterActionHandler.class);
 
   @Override
   public void beforeAction(ClusterActionEvent event)
       throws IOExceptionInterruptedException{
     if (event.getAction().equals()) {
       beforeBootstrap(event);
     } else if (event.getAction().equals()) {
       beforeConfigure(event);
     } else if (event.getAction().equals()) {
       beforeDestroy(event);
     } else {
       beforeOtherAction(event);
     }
   }
 
   @Override
   public void afterAction(ClusterActionEvent event)
       throws IOExceptionInterruptedException {
     if (event.getAction().equals()) {
       afterBootstrap(event);
     } else if (event.getAction().equals()) {
       afterConfigure(event);
     } else if (event.getAction().equals()) {
       afterDestroy(event);
     } else {
       afterOtherAction(event);
     }
   }
   
   protected void beforeBootstrap(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
   
   protected void beforeConfigure(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
 
   protected void beforeDestroy(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
 
   protected void beforeOtherAction(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
   
   protected void afterBootstrap(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
   
   protected void afterConfigure(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
   
   protected void afterDestroy(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
 
   protected void afterOtherAction(ClusterActionEvent event)
     throws IOExceptionInterruptedException { }
  
  
Returns a composite configuration that is made up from the global configuration coming from the Whirr core with the service default properties.

Parameters:
clusterSpec The cluster specification instance.
Returns:
The composite configuration.
      ClusterSpec clusterSpecConfiguration defaults) {
    cc.addConfiguration(clusterSpec.getConfiguration());
    cc.addConfiguration(defaults);
    return cc;
  }
  protected Configuration getConfiguration(ClusterSpec clusterSpec,
      String defaultsPropertiesFilethrows IOException {
    try {
      return getConfiguration(clusterSpec,
          new PropertiesConfiguration(defaultsPropertiesFile));
    } catch(ConfigurationException e) {
      throw new IOException("Error loading " + defaultsPropertiesFilee);
    }
 }
  
  
  public static void addRunUrl(ClusterActionEvent eventString runUrl,
      String... args)
      throws IOException {
    Statement statement = new RunUrlStatement(
        event.getClusterSpec().getRunUrlBase(), runUrlargs);
    addStatement(eventstatement);
  }
  public static void addStatement(ClusterActionEvent eventStatement statement) {
    event.getStatementBuilder().addStatement(statement);
  }

  
Prepare the file url for the remote machine. For public urls this function does nothing. For local urls it uploads the files to a temporary blob cache and adds download statement.

Parameters:
rawUrl raw url as provided in the configuration file
Returns:
an URL visible to the install / configure scripts
      throws IOException {
    if (rawUrl != null && rawUrl.startsWith("file://")) {
      try {
        URI uri = new URI(rawUrl);
        File localFile = new File(uri);
        BlobCache cache = BlobCache.getInstance(event.getCompute(), event.getClusterSpec());
        cache.putIfAbsent(localFile);
        final String basePath = "/tmp/whirr/cache/files/";
        addStatement(eventcache.getAsSaveToStatement(basePathuri));
        return "file://" + basePath + localFile.getName();
      } catch (URISyntaxException e) {
        throw new IOException(e);
      }
    } else if(rawUrl != null && rawUrl.startsWith("remote://")) {
      return rawUrl.replaceFirst("remote://""file://");
    }
    return rawUrl;
  }

  
Get service start function name from the configuration
  public String getStartFunction(Configuration configString serviceString defaultFunction) {
    return getFunctionName(configservice"start"defaultFunction);
  }

  
Get service start function name from the configuration
  public String getStopFunction(Configuration configString serviceString defaultFunction) {
    return getFunctionName(configservice"stop"defaultFunction);
  }

  
Get service install function name from the configuration
  public String getInstallFunction(Configuration configString serviceString defaultFunction) {
    return getFunctionName(configservice"install"defaultFunction);
  }

  
Get service configure function name from the configuration
  public String getConfigureFunction(Configuration configString serviceString defaultFunction) {
    return getFunctionName(configservice"configure"defaultFunction);
  }

  
Get service cleanup function name from the configuration
  public String getCleanupFunction(Configuration configString serviceString defaultFunction) {
    return getFunctionName(configservice"cleanup"defaultFunction);
  }
  public String getFunctionName(Configuration configString serviceString functionNameString defaultFunction) {
    String deprecatedKey = String.format("whirr.%s-%s-function"servicefunctionName);
    String key = String.format("whirr.%s.%s-function"servicefunctionName);
    if (config.containsKey(deprecatedKey)) {
      .warn("'{}' is deprecated. Replace with '{}'"deprecatedKeykey);
      return config.getString(deprecatedKey);
    }
    return config.getString(keydefaultFunction);
  }
New to GrepCode? Check out our FAQ X