<commit_before>/**
 * @author <NAME> (Ph.D.)
 * @mail <EMAIL>
 * 
 *       Copyright 2016 [<NAME>]
 * 
 *       Licensed 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 sonata.kernel.adaptor.wrapper;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import sonata.kernel.adaptor.StartServiceCallProcessor;
import sonata.kernel.adaptor.commons.DeployServiceData;
import sonata.kernel.adaptor.commons.DeployServiceResponse;
import sonata.kernel.adaptor.commons.ServiceRecord;
import sonata.kernel.adaptor.commons.Status;
import sonata.kernel.adaptor.commons.VDURecord;
import sonata.kernel.adaptor.commons.VNFRecord;
import sonata.kernel.adaptor.commons.vnfDescriptor.VNFDescriptor;
import sonata.kernel.adaptor.commons.vnfDescriptor.VirtualDeploymentUnit;

public class MockWrapper extends ComputeWrapper implements Runnable {

  /*
   * Utility fields to implement the mock response creation. A real wrapper should instantiate a
   * suitable object with these fields, able to handle the API call asynchronously, generate a
   * response and update the observer
   */
  private DeployServiceData data;
  private String SID;

  public MockWrapper(WrapperConfiguration config) {
    super();
  }

  @Override
  public boolean deployService(DeployServiceData data,
      final StartServiceCallProcessor callProcessor) {
    this.addObserver(callProcessor);
    this.data = data;
    this.SID = callProcessor.getSID();
    // This is a mock compute wrapper.

    /*
     * Just use the SD to forge the response message for the SLM with a success. In general Wrappers
     * would need a complex set of actions to deploy the service, so this function should just check
     * if the request is acceptable, and if so start a new thread to deal with the perform the
     * needed actions.
     */
    Thread t = new Thread(this);
    t.start();
    return true;
  }

  @Override
  public void run() {
    System.out.println("[MockWrapperFSM] - Deploying Service...");
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println("[MockWrapperFSM] - Service Deployed. Creating response");
    DeployServiceResponse response = new DeployServiceResponse();
    response.setStatus(Status.normal_operation);
    ServiceRecord sr = new ServiceRecord();
    sr.setId(UUID.randomUUID().toString());
    sr.setStatus(Status.normal_operation);

    for (VNFDescriptor vnf : data.getVNFDs()) {
      VNFRecord vnfr = new VNFRecord();
      vnfr.setDescriptor_version(vnf.getDescriptor_version());
      vnfr.setStatus(Status.normal_operation);
      vnfr.setVnf_address("0.0.0.0");
      vnfr.setId(UUID.randomUUID().toString());
      for (VirtualDeploymentUnit vdu : vnf.getVirtual_deployment_units()) {
        VDURecord vdur = new VDURecord();
        vdur.setId(UUID.randomUUID().toString());
        vdur.setNumber_of_instances(1);
        vdur.setVdu_reference(vnf.getName() + ":" + vdu.getId() + ":" + vdur.getId());
        vdur.setVm_image(vdu.getVm_image());
        vnfr.addVDU(vdur);
      }
      response.addVNFRecord(vnfr);
    }
    response.setNSR(sr);
    
    System.out.println("[MockWrapperFSM] - Response created. Serializing...");

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
    mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
    mapper.setSerializationInclusion(Include.NON_NULL);
    String body;
    try {
      body = mapper.writeValueAsString(response);
      this.setChanged();
      System.out.println("[MockWrapperFSM] - Serialized. notifying call processor");
      WrapperStatusUpdate update = new WrapperStatusUpdate(this.SID, "SUCCESS", body);
      this.notifyObservers(update);
    } catch (JsonProcessingException e) {
      e.printStackTrace();
    }
  }

}
<commit_msg>fixed a typo in vnfr description_version field<commit_after>/**
 * @author <NAME> (Ph.D.)
 * @mail <EMAIL>
 * 
 *       Copyright 2016 [<NAME>]
 * 
 *       Licensed 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 sonata.kernel.adaptor.wrapper;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import sonata.kernel.adaptor.StartServiceCallProcessor;
import sonata.kernel.adaptor.commons.DeployServiceData;
import sonata.kernel.adaptor.commons.DeployServiceResponse;
import sonata.kernel.adaptor.commons.ServiceRecord;
import sonata.kernel.adaptor.commons.Status;
import sonata.kernel.adaptor.commons.VDURecord;
import sonata.kernel.adaptor.commons.VNFRecord;
import sonata.kernel.adaptor.commons.vnfDescriptor.VNFDescriptor;
import sonata.kernel.adaptor.commons.vnfDescriptor.VirtualDeploymentUnit;

public class MockWrapper extends ComputeWrapper implements Runnable {

  /*
   * Utility fields to implement the mock response creation. A real wrapper should instantiate a
   * suitable object with these fields, able to handle the API call asynchronously, generate a
   * response and update the observer
   */
  private DeployServiceData data;
  private String SID;

  public MockWrapper(WrapperConfiguration config) {
    super();
  }

  @Override
  public boolean deployService(DeployServiceData data,
      final StartServiceCallProcessor callProcessor) {
    this.addObserver(callProcessor);
    this.data = data;
    this.SID = callProcessor.getSID();
    // This is a mock compute wrapper.

    /*
     * Just use the SD to forge the response message for the SLM with a success. In general Wrappers
     * would need a complex set of actions to deploy the service, so this function should just check
     * if the request is acceptable, and if so start a new thread to deal with the perform the
     * needed actions.
     */
    Thread t = new Thread(this);
    t.start();
    return true;
  }

  @Override
  public void run() {
    System.out.println("[MockWrapperFSM] - Deploying Service...");
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println("[MockWrapperFSM] - Service Deployed. Creating response");
    DeployServiceResponse response = new DeployServiceResponse();
    response.setStatus(Status.normal_operation);
    ServiceRecord sr = new ServiceRecord();
    sr.setId(UUID.randomUUID().toString());
    sr.setStatus(Status.normal_operation);

    for (VNFDescriptor vnf : data.getVNFDs()) {
      VNFRecord vnfr = new VNFRecord();
      vnfr.setDescriptor_version("vnfr-schema-01");
      vnfr.setStatus(Status.normal_operation);
      vnfr.setVnf_address("0.0.0.0");
      vnfr.setId(UUID.randomUUID().toString());
      for (VirtualDeploymentUnit vdu : vnf.getVirtual_deployment_units()) {
        VDURecord vdur = new VDURecord();
        vdur.setId(UUID.randomUUID().toString());
        vdur.setNumber_of_instances(1);
        vdur.setVdu_reference(vnf.getName() + ":" + vdu.getId() + ":" + vdur.getId());
        vdur.setVm_image(vdu.getVm_image());
        vnfr.addVDU(vdur);
      }
      response.addVNFRecord(vnfr);
    }
    response.setNSR(sr);
    
    System.out.println("[MockWrapperFSM] - Response created. Serializing...");

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
    mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
    mapper.setSerializationInclusion(Include.NON_NULL);
    String body;
    try {
      body = mapper.writeValueAsString(response);
      this.setChanged();
      System.out.println("[MockWrapperFSM] - Serialized. notifying call processor");
      WrapperStatusUpdate update = new WrapperStatusUpdate(this.SID, "SUCCESS", body);
      this.notifyObservers(update);
    } catch (JsonProcessingException e) {
      e.printStackTrace();
    }
  }

}

{'fraction_non_alphanumeric': 0.09934681837336705, 'fraction_numerical': 0.0037926675094816687, 'mean_word_length': 3.727589641434263, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107870', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2726, 'n_words': 692}