/**
  * 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);
   }
 }
예제 #2
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;
  }