/** test that if number of cpus is above threshold, agreement creation fails. */
  public void testAgreementCreationShouldFailIfCPUNumberAboveThreshold() {
    try {

      AgreementTemplateType template =
          getAgreementFactory().getTemplate(TEMPLATE_NAME, TEMPLATE_ID);
      AgreementOffer offer = new AgreementOfferType(template);
      XmlObject[] serviceXML = getServiceManifestXmlObject(offer);
      Manifest spManifest = getSPManifestFromXmlObject(serviceXML[0]);

      // set memory size 1 zero too much.
      spManifest
          .getVirtualMachineDescriptionSection()
          .getVirtualMachineComponentArray(0)
          .getOVFDefinition()
          .getVirtualSystem()
          .getVirtualHardwareSection()
          .setNumberOfVirtualCPUs(81920123);

      serviceXML[0].set(spManifest.toXmlBeanObject().getServiceManifest());

      AgreementClient agreementClient = getAgreementFactory().createAgreement(offer);

      assertNull("Agreement creation did not fail", agreementClient);

    } catch (Exception e) {
      System.out.println("Agreement creation should fail because of creation constraints");
      System.out.println(e.getMessage());
    }
  }
  public void testAgreementCreationFailsIfMaxInstancesAbove10() {
    try {

      AgreementTemplateType template =
          getAgreementFactory().getTemplate(TEMPLATE_NAME, TEMPLATE_ID);
      AgreementOffer offer = new AgreementOfferType(template);
      XmlObject[] serviceXML = getServiceManifestXmlObject(offer);
      Manifest spManifest = getSPManifestFromXmlObject(serviceXML[0]);

      spManifest
          .getVirtualMachineDescriptionSection()
          .getVirtualMachineComponentArray(0)
          .getAllocationConstraints()
          .setUpperBound(800);

      serviceXML[0].set(spManifest.toXmlBeanObject().getServiceManifest());

      AgreementClient agreementClient = null;

      agreementClient = getAgreementFactory().createAgreement(offer);

      assertNull("Agreement creation did not fail", agreementClient);

    } catch (Exception e) {
      System.out.println("Agreement creation should fail because of creation constraints");
      System.out.println(e.getMessage());
    }
  }
  /** agreement creation fails if size is above 512000 */
  public void testAgreementCreationShouldFailIfSizeAboveThreshold() {
    try {

      AgreementTemplateType template =
          getAgreementFactory().getTemplate(TEMPLATE_NAME, TEMPLATE_ID);
      AgreementOffer offer = new AgreementOfferType(template);
      XmlObject[] serviceXML = getServiceManifestXmlObject(offer);
      Manifest spManifest = getSPManifestFromXmlObject(serviceXML[0]);

      // set vm image size above threshold of 512000
      spManifest
          .getVirtualMachineDescriptionSection()
          .getVirtualMachineComponentArray(0)
          .getOVFDefinition()
          .getDiskSection()
          .getImageDisk()
          .setCapacity("1512000");
      serviceXML[0].set(spManifest.toXmlBeanObject().getServiceManifest());

      AgreementClient agreementClient = getAgreementFactory().createAgreement(offer);

      assertNull("Agreement creation did not fail", agreementClient);

    } catch (Exception e) {
      System.out.println("Agreement creation should fail because of creation constraints");
      System.out.println(e.getMessage());
    }
  }
Ejemplo n.º 4
0
 /**
  * Overloaded method for conversion of VM images until support is available in the Service
  * Manifest for specifying desired format. Given an object of ServiceManifest containing the
  * details of the service to be contextualized, this function performs a number of operations
  * asynchronously. TODO: Remove After year 2
  *
  * @param manifest Service Manifest to contextualize.
  * @param imageFormat Format to convert images to. Possible values are: "raw", "vmdk" and "qcow2"
  */
 public void contextualizeService(Manifest manifest, String imageFormat) {
   Runnable virtualMachineContextualizer =
       new VirtualMachineContextualizer(this, manifest, imageFormat);
   Thread thread = new Thread(virtualMachineContextualizer);
   threads.put(manifest.getManifestId(), thread);
   thread.start();
 }
Ejemplo n.º 5
0
  /**
   * Tests the progress object callback function when we are 100% sure the state data has been
   * initialised.
   */
  public void testContextualizeServiceWorkflow() {
    log.info("### TEST: " + getCurrentMethodName() + " STARTED ###");

    ProgressData progressData = null;

    try {
      // Decide which manifest we are going to test with
      Manifest manifest;
      if (testManifest != null) {
        manifest = testManifest;
      } else {
        String serviceId = "3";
        manifest = Manifest.Factory.newInstance(serviceId, "jboss");
      }

      log.info("TEST: Service manifest is:\n" + manifest.toString());

      // Initialise the VMC's configuration providing the path of the
      // config.properties file...
      GlobalConfiguration globalConfiguration;
      if (configFilePath != null) {
        globalConfiguration = new GlobalConfiguration(configFilePath);
      } else {
        globalConfiguration = new GlobalConfiguration();
      }
      VmcApi vmcApi = new VmcApi(globalConfiguration);

      if (imageFormat == null) {
        vmcApi.contextualizeService(manifest);
      } else {
        vmcApi.contextualizeService(manifest, imageFormat);
      }

      // Wait until the service has been registered with the VMC before
      // polling the progress data...
      while (true) {
        try {
          log.info("TEST: Trying to fetch progress data...");
          vmcApi.contextualizeServiceCallback(manifest.getManifestId());
          log.info("TEST: No ProgressException...");
          break;
        } catch (ProgressException e) {
          log.warn("TEST: Caught ProgressException due to: " + e.getMessage());
          Thread.sleep(250);
        }
      }

      // Poll the progress data until the completion...
      while (true) {

        // We have progress data, do something with it...
        progressData = vmcApi.contextualizeServiceCallback(manifest.getManifestId());

        // We have an error so stop everything!
        if (progressData.isError()) {
          // Say what the error is...
          log.error(progressData.getException().getMessage(), progressData.getException());
          assertFalse(progressData.isError()); // For test case to
          // report failure
          // correctly
          return;
        } else {
          log.info(
              "TEST: contextualizeServiceCallbackObject total progress is: "
                  + progressData.getTotalProgress());
          log.info(
              "TEST: contextualizeServiceCallbackObject phase history of Phase with ID: "
                  + progressData.getPhaseName(progressData.getCurrentPhaseId())
                  + ", % is: "
                  + progressData.getHistory().get(progressData.getCurrentPhaseId()));
        }

        // 250ms delay between polling...
        Thread.sleep(250);

        // Test to see if contextualization has finished...
        if (vmcApi.contextualizeServiceCallback(manifest.getManifestId()).isComplete()) {
          log.warn("TEST: Detected contextualization has completed!");
          break;
        }
      }

      // Test that the new manifest has been set...
      assertTrue(progressData.getManifest() != null);
      log.info(
          "TEST: contextualizeServiceCallbackObject altered manifest is: \n"
              + progressData.getManifest().toString());

      // Test that the history is saved correctly in the progress data.
      for (int i = 0; i < progressData.getHistory().size(); i++) {
        log.info(
            "TEST: contextualizeServiceCallbackObject history of Phase with ID: "
                + progressData.getPhaseName(i)
                + ", % is: "
                + progressData.getHistory().get(i));
      }

    } catch (Exception e) {
      log.error("TEST: Test Failed! Cause: " + e.getCause(), e);
    }

    log.warn("### TEST: " + getCurrentMethodName() + " COMPLETE ###");
  }