/**
  * Update or create a Datasource file
  *
  * @param deploymentFile
  * @param name
  * @param report
  */
 public static void updateDatasource(
     File deploymentFile, String name, CreateResourceReport report) {
   try {
     updateDatasource(deploymentFile, name, report.getResourceConfiguration());
     report.setStatus(CreateResourceStatus.SUCCESS);
   } catch (IOException e) {
     report.setException(e);
     log.error("IO error occurred while updating datasource at file: " + deploymentFile, e);
   } catch (JDOMException e) {
     report.setException(e);
     log.error("Parsing error occurred while updating datasource at file: " + deploymentFile, e);
   }
 }
Beispiel #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.rhq.core.pluginapi.inventory.CreateChildResourceFacet#createResource
   * (org.rhq.core.pluginapi.inventory.CreateResourceReport)
   */
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {
    ResourceType resourceType = report.getResourceType();
    // if (resourceType.getName().equals("Translators")) {
    // createConfigurationBasedResource(report);
    // } else {
    createContentBasedResource(report);
    // }

    return report;
  }
Beispiel #3
0
  /**
   * Deploy content to the remote server - this is one half of #createResource
   *
   * @param report Create resource report that tells us what to do
   * @return report that tells us what has been done.
   */
  protected CreateResourceReport deployContent(CreateResourceReport report) {
    ContentContext cctx = context.getContentContext();
    ResourcePackageDetails details = report.getPackageDetails();

    ContentServices contentServices = cctx.getContentServices();
    String resourceTypeName = report.getResourceType().getName();

    ASUploadConnection uploadConnection = new ASUploadConnection(host, port);
    OutputStream out = uploadConnection.getOutputStream(details.getFileName());
    contentServices.downloadPackageBitsForChildResource(
        cctx, resourceTypeName, details.getKey(), out);

    JsonNode uploadResult = uploadConnection.finishUpload();
    if (verbose) log.info(uploadResult);

    if (ASUploadConnection.isErrorReply(uploadResult)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(ASUploadConnection.getFailureDescription(uploadResult));

      return report;
    }

    String fileName = details.getFileName();

    if (fileName.startsWith(
        "C:\\fakepath\\")) { // TODO this is a hack as the server adds the fake path somehow
      fileName = fileName.substring("C:\\fakepath\\".length());
    }

    String tmpName = fileName; // TODO figure out the tmp-name biz with the AS guys

    JsonNode resultNode = uploadResult.get("result");
    String hash = resultNode.get("BYTES_VALUE").getTextValue();

    return runDeploymentMagicOnServer(report, fileName, tmpName, hash);
  }
Beispiel #4
0
  protected void createContentBasedResource(CreateResourceReport createResourceReport) {

    Property versionProp =
        createResourceReport
            .getPackageDetails()
            .getDeploymentTimeConfiguration()
            .get(Operation.Value.VDB_VERSION);
    String name = createResourceReport.getPackageDetails().getKey().getName();
    name = name.substring(name.lastIndexOf(File.separatorChar) + 1);
    String userSpecifiedName = createResourceReport.getUserSpecifiedResourceName();
    String deployName = (userSpecifiedName != null ? userSpecifiedName : name);

    if (versionProp != null) {

      Integer vdbVersion = ((PropertySimple) versionProp).getIntegerValue();
      // strip off vdb extension if user added it
      if (deployName.endsWith(DQPManagementView.VDB_EXT)) {
        deployName = deployName.substring(0, deployName.lastIndexOf(DQPManagementView.VDB_EXT));
      }
      if (vdbVersion != null) {
        deployName =
            deployName
                + "."
                + ((Integer) vdbVersion).toString()
                + DQPManagementView.VDB_EXT; // $NON-NLS-1$
      }
      // add vdb extension if there was no version
      if (!deployName.endsWith(DQPManagementView.VDB_EXT)
          && !deployName.endsWith(DQPManagementView.DYNAMIC_VDB_EXT)) {
        deployName = deployName + DQPManagementView.VDB_EXT;
      }

      // null out version
      PropertySimple nullVersionProperty = new PropertySimple(Operation.Value.VDB_VERSION, null);
      createResourceReport
          .getPackageDetails()
          .getDeploymentTimeConfiguration()
          .put(nullVersionProperty);
      createResourceReport.setUserSpecifiedResourceName(deployName);
    }

    getDeployer().deploy(createResourceReport, createResourceReport.getResourceType());
  }
Beispiel #5
0
  /**
   * Do the actual fumbling with the domain api to deploy the uploaded content
   *
   * @param report CreateResourceReport to report the result
   * @param runtimeName File name to use as runtime name
   * @param deploymentName Name of the deployment
   * @param hash Hash of the content bytes
   * @return the passed report with success or failure settings
   */
  public CreateResourceReport runDeploymentMagicOnServer(
      CreateResourceReport report, String runtimeName, String deploymentName, String hash) {

    boolean toServerGroup = context.getResourceKey().contains("server-group=");
    log.info("Deploying [" + runtimeName + "] to domain only= " + !toServerGroup + " ...");

    ASConnection connection = getASConnection();

    Operation step1 = new Operation("add", "deployment", deploymentName);
    //        step1.addAdditionalProperty("hash", new PROPERTY_VALUE("BYTES_VALUE", hash));
    List<Object> content = new ArrayList<Object>(1);
    Map<String, Object> contentValues = new HashMap<String, Object>();
    contentValues.put("hash", new PROPERTY_VALUE("BYTES_VALUE", hash));
    content.add(contentValues);
    step1.addAdditionalProperty("content", content);

    step1.addAdditionalProperty("name", deploymentName);
    step1.addAdditionalProperty("runtime-name", runtimeName);

    String resourceKey;
    Result result;

    CompositeOperation cop = new CompositeOperation();
    cop.addStep(step1);
    /*
     * We need to check here if this is an upload to /deployment only
     * or if this should be deployed to a server group too
     */

    if (!toServerGroup) {

      // if standalone, then :deploy the deployment anyway
      if (context.getResourceType().getName().contains("Standalone")) {
        Operation step2 = new Operation("deploy", step1.getAddress());
        cop.addStep(step2);
      }

      result = connection.execute(cop);
      resourceKey = step1.getAddress().getPath();

    } else {

      Address serverGroupAddress = new Address(context.getResourceKey());
      serverGroupAddress.add("deployment", deploymentName);
      Operation step2 = new Operation("add", serverGroupAddress);

      cop.addStep(step2);

      Operation step3 = new Operation("deploy", serverGroupAddress);
      cop.addStep(step3);

      resourceKey = serverGroupAddress.getPath();

      if (verbose) log.info("Deploy operation: " + cop);

      result = connection.execute(cop);
    }

    if ((!result.isSuccess())) {
      String failureDescription = result.getFailureDescription();
      report.setErrorMessage(failureDescription);
      report.setStatus(CreateResourceStatus.FAILURE);
      log.warn(" ... done with failure: " + failureDescription);
    } else {
      report.setStatus(CreateResourceStatus.SUCCESS);
      report.setResourceName(runtimeName);
      report.setResourceKey(resourceKey);
      log.info(" ... with success and key [" + resourceKey + "]");
    }

    return report;
  }
Beispiel #6
0
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {

    if (report.getPackageDetails() != null) { // Content deployment
      return deployContent(report);
    } else {
      report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
      Address createAddress = new Address(address);
      createAddress.add(
          report.getPluginConfiguration().getSimpleValue("path", ""),
          report.getUserSpecifiedResourceName());
      Operation op = new Operation("add", createAddress);
      for (Property prop : report.getResourceConfiguration().getProperties()) {
        if (prop instanceof PropertySimple) {
          PropertySimple ps = (PropertySimple) prop;
          String value = ps.getStringValue();
          op.addAdditionalProperty(prop.getName(), value);
        }
        // TODO more types
      }
      Result result = getASConnection().execute(op);
      if (result.isSuccess()) {
        report.setStatus(CreateResourceStatus.SUCCESS);
        report.setResourceKey(address.getPath());
        report.setResourceName(report.getUserSpecifiedResourceName());
      } else {
        report.setStatus(CreateResourceStatus.FAILURE);
        report.setErrorMessage(result.getFailureDescription());
      }
    }
    return report;
  }
  public CreateResourceReport createResource(CreateResourceReport report) {

    JBossASServerComponent parentResourceComponent =
        getResourceContext().getParentResourceComponent();

    String resourceTypeName = report.getResourceType().getName();

    String objectNamePreString;
    boolean isTopic = false;
    if (resourceTypeName.contains("Topic")) {
      objectNamePreString = TOPIC_MBEAN_NAME;
      isTopic = true;
    } else {
      objectNamePreString = QUEUE_MBEAN_NAME;
    }

    Configuration config = report.getResourceConfiguration();

    String name = config.getSimple("MBeanName").getStringValue();
    PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate");
    String rName = nameTemplateProp.getStringValue();
    //noinspection ConstantConditions
    rName = rName.replace("{name}", name);

    EmsConnection connection = parentResourceComponent.getEmsConnection();

    if (DeploymentUtility.isDuplicateJndiName(connection, objectNamePreString, name)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage("Duplicate JNDI Name, a resource with that name already exists");
      return report;
    }
    PropertySimple pluginNameProperty = new PropertySimple("name", rName);
    getResourceContext().getPluginConfiguration().put(pluginNameProperty);

    File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy");
    File deploymentFile =
        new File(deployDir, FileNameUtility.formatFileName(name) + "-destination-service.xml");

    xmlEditor = new JBossMessagingConfigurationEditor(resourceTypeName);
    xmlEditor.updateConfiguration(deploymentFile, name, report);
    try {
      parentResourceComponent.deployFile(deploymentFile);
    } catch (Exception e) {
      JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e);
      return report;
    }

    // This key needs to be the same as the object name string used in discovery, defined in the
    // plugin descriptor
    //   jboss.messaging.destination:service=<Queue|Topic>,name=%name%
    String serviceString = (isTopic ? "Topic" : "Queue");

    String objectName = "jboss.messaging.destination:name=" + name + ",service=" + serviceString;
    try {
      // IMPORTANT: The object name must be canonicalized so it matches the resource key that
      //            MBeanResourceDiscoveryComponent uses, which is the canonical object name.
      objectName = getCanonicalName(objectName);
      report.setResourceKey(objectName);
    } catch (MalformedObjectNameException e) {
      log.warn("Invalid key [" + objectName + "]: " + e.getMessage());
      return report;
    }
    report.setResourceName(rName);

    try {
      Thread.sleep(5000L);
    } catch (InterruptedException e) {
      log.info("Sleep after datasource create interrupted", e);
      Thread.currentThread().interrupt();
    }

    return report;
  }
Beispiel #8
0
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {
    report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
    Address createAddress = new Address(this.address);

    String path = report.getPluginConfiguration().getSimpleValue("path", "");
    String resourceName;
    if (!path.contains("=")) {
      // this is not a singleton subsystem
      // resources like  example=test1 and example=test2 can be created
      resourceName = report.getUserSpecifiedResourceName();
    } else {
      // this is a request to create a true singleton subsystem
      // both the path and the name are set at resource level configuration
      resourceName = path.substring(path.indexOf('=') + 1);
      path = path.substring(0, path.indexOf('='));
    }

    createAddress.add(path, resourceName);

    Operation op = new Operation("add", createAddress);
    for (Property prop : report.getResourceConfiguration().getProperties()) {
      SimpleEntry<String, ?> entry = null;

      boolean isEntryEligible = true;
      if (prop instanceof PropertySimple) {
        PropertySimple propertySimple = (PropertySimple) prop;
        PropertyDefinitionSimple propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionSimple(propertySimple.getName());

        if (propertyDefinition == null
            || (!propertyDefinition.isRequired() && propertySimple.getStringValue() == null)) {
          isEntryEligible = false;
        } else {
          entry = preparePropertySimple(propertySimple, propertyDefinition);
        }
      } else if (prop instanceof PropertyList) {
        PropertyList propertyList = (PropertyList) prop;
        PropertyDefinitionList propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionList(propertyList.getName());

        if (!propertyDefinition.isRequired() && propertyList.getList().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyList(propertyList, propertyDefinition);
        }
      } else if (prop instanceof PropertyMap) {
        PropertyMap propertyMap = (PropertyMap) prop;
        PropertyDefinitionMap propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionMap(propertyMap.getName());

        if (!propertyDefinition.isRequired() && propertyMap.getMap().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyMap(propertyMap, propertyDefinition);
        }
      }

      if (isEntryEligible) {
        op.addAdditionalProperty(entry.getKey(), entry.getValue());
      }
    }

    Result result = this.connection.execute(op);
    if (result.isSuccess()) {
      report.setStatus(CreateResourceStatus.SUCCESS);
      report.setResourceKey(createAddress.getPath());
      report.setResourceName(report.getUserSpecifiedResourceName());
    } else {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(result.getFailureDescription());
    }

    return report;
  }
Beispiel #9
0
  private CreateResourceReport createConfigurationBasedResource(
      CreateResourceReport createResourceReport) {
    ResourceType resourceType = createResourceReport.getResourceType();
    Configuration defaultPluginConfig = getDefaultPluginConfiguration(resourceType);
    Configuration resourceConfig = createResourceReport.getResourceConfiguration();
    String resourceName = getResourceName(defaultPluginConfig, resourceConfig);
    ComponentType componentType = ProfileServiceUtil.getComponentType(resourceType);
    ManagementView managementView = null;
    ;
    managementView = getConnection().getManagementView();

    if (ProfileServiceUtil.isManagedComponent(getConnection(), resourceName, componentType)) {
      createResourceReport.setStatus(CreateResourceStatus.FAILURE);
      createResourceReport.setErrorMessage(
          "A "
              + resourceType.getName() // $NON-NLS-1$
              + " named '"
              + resourceName
              + "' already exists."); //$NON-NLS-1$ //$NON-NLS-2$
      return createResourceReport;
    }

    createResourceReport.setResourceName(resourceName);
    String resourceKey = getResourceKey(resourceType, resourceName);
    createResourceReport.setResourceKey(resourceKey);

    PropertySimple templateNameProperty =
        resourceConfig.getSimple(TranslatorComponent.Config.TEMPLATE_NAME);
    String templateName = templateNameProperty.getStringValue();

    DeploymentTemplateInfo template;
    try {
      template = managementView.getTemplate(templateName);
      Map<String, ManagedProperty> managedProperties = template.getProperties();

      ProfileServiceUtil.convertConfigurationToManagedProperties(
          managedProperties, resourceConfig, resourceType, null);

      LOG.debug(
          "Applying template ["
              + templateName //$NON-NLS-1$
              + "] to create ManagedComponent of type ["
              + componentType //$NON-NLS-1$
              + "]..."); //$NON-NLS-1$
      try {
        managementView.applyTemplate(resourceName, template);
        managementView.process();
        createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
      } catch (Exception e) {
        LOG.error(
            "Unable to apply template ["
                + templateName //$NON-NLS-1$
                + "] to create ManagedComponent of type " //$NON-NLS-1$
                + componentType
                + ".",
            e); //$NON-NLS-1$
        createResourceReport.setStatus(CreateResourceStatus.FAILURE);
        createResourceReport.setException(e);
      }
    } catch (NoSuchDeploymentException e) {
      LOG.error("Unable to find template [" + templateName + "].", e); // $NON-NLS-1$ //$NON-NLS-2$
      createResourceReport.setStatus(CreateResourceStatus.FAILURE);
      createResourceReport.setException(e);
    } catch (Exception e) {
      LOG.error("Unable to process create request", e); // $NON-NLS-1$
      createResourceReport.setStatus(CreateResourceStatus.FAILURE);
      createResourceReport.setException(e);
    }
    return createResourceReport;
  }