Пример #1
0
 private String getResourceKey(ResourceType resourceType, String resourceName) {
   ComponentType componentType = ProfileServiceUtil.getComponentType(resourceType);
   if (componentType == null)
     throw new IllegalStateException(
         "Unable to map "
             + resourceType //$NON-NLS-1$
             + " to a ComponentType."); //$NON-NLS-1$
   return componentType.getType()
       + ":"
       + componentType.getSubtype()
       + ":" //$NON-NLS-1$ //$NON-NLS-2$
       + resourceName;
 }
Пример #2
0
  /**
   * The plugin container will call this method when it has a new configuration for your managed
   * resource. Your plugin will re-configure the managed resource in your own custom way, setting
   * its configuration based on the new values of the given configuration.
   *
   * @see ConfigurationFacet#updateResourceConfiguration(ConfigurationUpdateReport)
   */
  public void updateResourceConfiguration(ConfigurationUpdateReport report) {

    resourceConfiguration = report.getConfiguration().deepCopy();

    Configuration resourceConfig = report.getConfiguration();

    ManagementView managementView = null;
    ComponentType componentType = null;
    if (this.getComponentType().equals(PluginConstants.ComponentType.VDB.NAME)) {
      componentType =
          new ComponentType(
              PluginConstants.ComponentType.VDB.TYPE, PluginConstants.ComponentType.VDB.SUBTYPE);
    } else {
      report.setStatus(ConfigurationUpdateStatus.FAILURE);
      report.setErrorMessage("Update not implemented for the component type."); // $NON-NLS-1$
    }

    ManagedComponent managedComponent = null;
    report.setStatus(ConfigurationUpdateStatus.SUCCESS);
    try {

      managementView = getConnection().getManagementView();
      managedComponent = managementView.getComponent(this.name, componentType);
      Map<String, ManagedProperty> managedProperties = managedComponent.getProperties();

      ProfileServiceUtil.convertConfigurationToManagedProperties(
          managedProperties, resourceConfig, resourceContext.getResourceType(), null);

      try {
        managementView.updateComponent(managedComponent);
      } catch (Exception e) {
        LOG.error(
            "Unable to update component [" //$NON-NLS-1$
                + managedComponent.getName()
                + "] of type " //$NON-NLS-1$
                + componentType
                + ".",
            e); //$NON-NLS-1$
        report.setStatus(ConfigurationUpdateStatus.FAILURE);
        report.setErrorMessageFromThrowable(e);
      }
    } catch (Exception e) {
      LOG.error("Unable to process update request", e); // $NON-NLS-1$
      report.setStatus(ConfigurationUpdateStatus.FAILURE);
      report.setErrorMessageFromThrowable(e);
    }
  }
Пример #3
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;
  }