当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleEvent.getLifecycle_events方法代码示例

本文整理汇总了Java中org.openbaton.catalogue.mano.common.LifecycleEvent.getLifecycle_events方法的典型用法代码示例。如果您正苦于以下问题:Java LifecycleEvent.getLifecycle_events方法的具体用法?Java LifecycleEvent.getLifecycle_events怎么用?Java LifecycleEvent.getLifecycle_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openbaton.catalogue.mano.common.LifecycleEvent的用法示例。


在下文中一共展示了LifecycleEvent.getLifecycle_events方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareLifecycleScript

import org.openbaton.catalogue.mano.common.LifecycleEvent; //导入方法依赖的package包/类
/**
 * Write the lifecycle scripts into a special directory in the charm so that they can be called by
 * the charm hooks. TODO
 *
 * @param fileName
 * @param nsId
 * @param vnfName
 * @param le
 * @throws Exception
 */
private void prepareLifecycleScript(
    String fileName, String nsId, String vnfName, LifecycleEvent le) throws Exception {
  File file = new File("/tmp/openbaton/juju/" + nsId + "/" + vnfName + "/hooks/" + fileName);
  if (!file.exists()) {
    file.createNewFile();
    Files.setPosixFilePermissions(file.toPath(), permissions);
  }

  String fileContent =
      "#!/bin/bash\necho \"`date '+%H-%M-%S'` "
          + vnfName
          + ": execute "
          + fileName
          + " hook\" >> "
          + scriptLogPath
          + "/"
          + vnfName
          + "\nsource hooks/paramVariables\n";
  fileContent += ("cd scripts\n");
  for (String scriptName : le.getLifecycle_events())
    fileContent +=
        ("echo \"`date '+%H-%M-%S'` "
            + vnfName
            + ": execute "
            + scriptName
            + "\" >> "
            + scriptLogPath
            + "/"
            + vnfName
            + "\nbash "
            + scriptName
            + "\necho \"`date '+%H-%M-%S'` "
            + vnfName
            + ": finished "
            + scriptName
            + "\" >> "
            + scriptLogPath
            + "/"
            + vnfName
            + "\n");
  fileContent +=
      "echo \"`date '+%H-%M-%S'` "
          + vnfName
          + ": finished "
          + fileName
          + " hook\" >> "
          + scriptLogPath
          + "/"
          + vnfName
          + "\n";
  try {
    Files.write(
        Paths.get(file.getAbsolutePath()), fileContent.getBytes(), StandardOpenOption.APPEND);
  } catch (IOException e) {
    log.error("Could not write to " + fileName + " file");
  }
}
 
开发者ID:openbaton,项目名称:juju-vnfm,代码行数:68,代码来源:JujuVnfm.java

示例2: copyLifecycleScripts

import org.openbaton.catalogue.mano.common.LifecycleEvent; //导入方法依赖的package包/类
/**
 * Copy the lifecycle scripts into the correct charm.
 *
 * @param le
 * @param event
 * @param vnfdName
 * @return
 * @throws Exception
 */
private void copyLifecycleScripts(LifecycleEvent le, Event event, String vnfdName, String nsId)
    throws Exception {
  log.info("Copy scripts for lifecycle event " + event.name());

  File scriptsFolder = new File("/tmp/openbaton/juju/" + nsId + "/scripts/" + vnfdName);
  File[] listOfFiles = scriptsFolder.listFiles();
  if (listOfFiles.length > 1)
    throw new Exception(
        "There is more than one folder in /tmp/openbaton/juju/scripts/" + vnfdName);
  else if (listOfFiles.length < 1)
    throw new Exception(
        "No script folder found in /tmp/openbaton/juju/" + nsId + "/scripts/" + vnfdName);

  String gitFolderPath = "";

  for (int i = 0; i < listOfFiles.length; i++) {
    if (listOfFiles[i].isFile()) {
      throw new Exception(
          "Git Repository expected but just found a normal file: " + listOfFiles[i].getName());
    } else if (listOfFiles[i].isDirectory()) {
      gitFolderPath = listOfFiles[i].getPath();
    }
  }
  log.info("Found git folder " + gitFolderPath);

  String dirName = event.name().toLowerCase() + "Scripts";
  File scriptDir = new File("/tmp/openbaton/juju/" + nsId + "/" + vnfdName + "/hooks/" + dirName);
  if (!scriptDir.exists())
    (new File(
            "/tmp/openbaton/juju/"
                + nsId
                + "/"
                + vnfdName
                + "/hooks/"
                + le.getEvent().name().toLowerCase()
                + "Scripts"))
        .mkdirs();

  for (String script : le.getLifecycle_events()) {
    Files.copy(
        Paths.get(gitFolderPath + "/" + script),
        Paths.get(
            "/tmp/openbaton/juju/" + nsId + "/" + vnfdName + "/hooks/" + dirName + "/" + script),
        StandardCopyOption.COPY_ATTRIBUTES);
  }
}
 
开发者ID:openbaton,项目名称:juju-vnfm,代码行数:56,代码来源:JujuVnfm.java

示例3: executeScriptsForEvent

import org.openbaton.catalogue.mano.common.LifecycleEvent; //导入方法依赖的package包/类
public Iterable<String> executeScriptsForEvent(
    VirtualNetworkFunctionRecord virtualNetworkFunctionRecord, Event event)
    throws Exception { //TODO make it parallel
  Map<String, String> env = getMap(virtualNetworkFunctionRecord);
  Collection<String> res = new ArrayList<>();
  LifecycleEvent le =
      VnfmUtils.getLifecycleEvent(virtualNetworkFunctionRecord.getLifecycle_event(), event);

  if (le != null) {
    log.trace(
        "The number of scripts for "
            + virtualNetworkFunctionRecord.getName()
            + " are: "
            + le.getLifecycle_events());
    for (String script : le.getLifecycle_events()) {
      log.info(
          "Sending script: "
              + script
              + " to VirtualNetworkFunctionRecord: "
              + virtualNetworkFunctionRecord.getName());
      for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) {
        for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) {

          Map<String, String> tempEnv = new HashMap<>();
          for (Ip ip : vnfcInstance.getIps()) {
            log.debug("Adding net: " + ip.getNetName() + " with value: " + ip.getIp());
            tempEnv.put(ip.getNetName(), ip.getIp());
          }
          log.debug("adding floatingIp: " + vnfcInstance.getFloatingIps());
          for (Ip fip : vnfcInstance.getFloatingIps()) {
            tempEnv.put(fip.getNetName() + "_floatingIp", fip.getIp());
          }

          tempEnv.put("hostname", vnfcInstance.getHostname());
          tempEnv = modifyUnsafeEnvVarNames(tempEnv);
          env.putAll(tempEnv);
          log.info("Environment Variables are: " + env);

          String command = JsonUtils.getJsonObject("EXECUTE", script, env).toString();
          String output =
              ems.executeActionOnEMS(
                  vnfcInstance.getHostname(),
                  command,
                  virtualNetworkFunctionRecord,
                  vnfcInstance);
          res.add(output);
          log.debug("Saving log to file...");
          logUtils.saveLogToFile(virtualNetworkFunctionRecord, script, vnfcInstance, output);
          for (String key : tempEnv.keySet()) {
            env.remove(key);
          }
        }
      }
    }
  }
  return res;
}
 
开发者ID:openbaton,项目名称:generic-vnfm,代码行数:58,代码来源:LifeCycleManagement.java


注:本文中的org.openbaton.catalogue.mano.common.LifecycleEvent.getLifecycle_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。