Example #1
0
  @Override
  public VirtualNetworkFunctionRecord heal(
      VirtualNetworkFunctionRecord virtualNetworkFunctionRecord,
      VNFCInstance component,
      String cause)
      throws Exception {

    if ("switchToStandby".equals(cause)) {
      for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionRecord.getVdu()) {
        for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) {
          if (vnfcInstance.getId().equals(component.getId())
              && "standby".equalsIgnoreCase(vnfcInstance.getState())) {
            log.debug("Activation of the standby component");
            if (VnfmUtils.getLifecycleEvent(
                    virtualNetworkFunctionRecord.getLifecycle_event(), Event.START)
                != null) {
              log.debug(
                  "Executed scripts for event START "
                      + this.executeScriptsForEvent(
                          virtualNetworkFunctionRecord, component, Event.START));
            }
            log.debug("Changing the status from standby to active");
            // This is inside the vnfr
            vnfcInstance.setState("ACTIVE");
            // This is a copy of the object received as parameter and modified.
            // It will be sent to the orchestrator
            component.setState("ACTIVE");
            break;
          }
        }
      }
    } else if (VnfmUtils.getLifecycleEvent(
            virtualNetworkFunctionRecord.getLifecycle_event(), Event.HEAL)
        != null) {
      if (VnfmUtils.getLifecycleEvent(virtualNetworkFunctionRecord.getLifecycle_event(), Event.HEAL)
              .getLifecycle_events()
          != null) {
        log.debug("Heal method started");
        log.info("-----------------------------------------------------------------------");
        String output = "\n--------------------\n--------------------\n";
        for (String result :
            executeScriptsForEvent(virtualNetworkFunctionRecord, component, Event.HEAL, cause)) {
          output +=
              this.parser
                  .fromJson(result, JsonObject.class)
                  .get("output")
                  .getAsString()
                  .replaceAll("\\\\n", "\n");
          output += "\n--------------------\n";
        }
        output += "\n--------------------\n";
        log.info("Executed script for HEAL. Output was: \n\n" + output);
        log.info("-----------------------------------------------------------------------");
      }
    }
    return virtualNetworkFunctionRecord;
  }
Example #2
0
  private String executeActionOnEMS(
      String vduHostname,
      String command,
      VirtualNetworkFunctionRecord vnfr,
      VNFCInstance vnfcInstance)
      throws Exception {
    log.trace("Sending message and waiting: " + command + " to " + vduHostname);
    log.info("Waiting answer from EMS - " + vduHostname);

    String response =
        this.vnfmHelper.sendAndReceive(command, "vnfm." + vduHostname.toLowerCase() + ".actions");

    log.debug("Received from EMS (" + vduHostname + "): " + response);

    if (response == null) {
      throw new NullPointerException("Response from EMS is null");
    }

    JsonObject jsonObject = this.parser.fromJson(response, JsonObject.class);

    if (jsonObject.get("status").getAsInt() == 0) {
      try {
        log.debug("Output from EMS (" + vduHostname + ") is: " + jsonObject.get("output"));
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      }
    } else {
      String err = jsonObject.get("err").getAsString();
      log.error(err);
      vnfcInstance.setState("error");
      saveLogToFile(
          vnfr,
          parser.fromJson(command, JsonObject.class).get("payload").getAsString(),
          vnfcInstance,
          response,
          true);
      throw new VnfmSdkException("EMS (" + vduHostname + ") had the following error: " + err);
    }
    return response;
  }