本文整理汇总了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");
}
}
示例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);
}
}
示例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;
}