Search in sources :

Example 16 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class Poll method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("", POLL_NEW_NAME).apply(element);
        addMigrationAttributeToElement(element, new Attribute("isMessageSource", "true"));
        List<Element> childElementsToMove = element.getChildren().stream().filter(s -> !StringUtils.equals(s.getName(), FIXED_FREQ_SCHEDULER) && !StringUtils.equals(s.getName(), CRON_FREQ_SCHEDULER) && !StringUtils.equals(s.getName(), WATERMARK)).collect(toList());
        movePollChildsToParent(childElementsToMove, element.getParentElement(), element.getParentElement().indexOf(element) + 1);
        if (element.getChild(FIXED_FREQ_SCHEDULER, CORE_NAMESPACE) == null && element.getChild(CRON_FREQ_SCHEDULER, SCHEDULERS_NAMESPACE) == null) {
            Element schedulingStrategy = new Element("scheduling-strategy", element.getNamespace());
            final Element fixedFrequency = new Element("fixed-frequency", element.getNamespace());
            schedulingStrategy.addContent(fixedFrequency);
            element.addContent(schedulingStrategy);
            // support the `frequency` attribute that was deprecated in 3.5.0
            final String newFrequency = changeDefault("1000", "60000", element.getAttributeValue("frequency"));
            if (newFrequency != null) {
                fixedFrequency.setAttribute("frequency", newFrequency);
            }
            element.removeAttribute("frequency");
        } else {
            updateCronScheduler(element);
            updateFixedFrequencyScheduler(element);
        }
        if (element.getChild(WATERMARK, CORE_NAMESPACE) != null) {
            Element watermark = element.getChild(WATERMARK, CORE_NAMESPACE);
            Element osStore = new Element("store", NEW_OS_NAMESPACE);
            Element osRetrieve = new Element("retrieve", NEW_OS_NAMESPACE);
            addMigrationAttributeToElement(osStore, new Attribute("lastElement", "true"));
            osStore.setAttribute("failIfPresent", "false");
            osStore.setAttribute("failOnNullValue", "false");
            if (watermark.getAttribute("variable") != null) {
                osStore.setAttribute("key", watermark.getAttributeValue("variable"));
                osRetrieve.setAttribute("key", watermark.getAttributeValue("variable"));
                osRetrieve.setAttribute("target", watermark.getAttributeValue("variable"));
            }
            if (watermark.getAttribute("default-expression") != null) {
                String defaultExpression = getExpressionMigrator().migrateExpression(watermark.getAttributeValue("default-expression"), true, element);
                setOSValue(osRetrieve, defaultExpression, "default-value");
            }
            if (watermark.getAttribute("update-expression") != null) {
                String updateExpression = getExpressionMigrator().migrateExpression(watermark.getAttributeValue("update-expression"), true, element);
                setOSValue(osStore, updateExpression, "value");
            } else if (watermark.getAttribute("selector-expression") != null || watermark.getAttribute("selector") != null) {
                String selectorExpression = watermark.getAttributeValue("selector-expression");
                String selector = watermark.getAttributeValue("selector");
                if (selectorExpression == null) {
                    setOSValue(osStore, getExpressionFromSelector(selector), "value");
                } else if (selector == null) {
                    selectorExpression = getExpressionMigrator().migrateExpression(selectorExpression, true, element);
                    setOSValue(osStore, selectorExpression, "value");
                } else {
                    selectorExpression = watermarkSelectorMigrator.migrateSelector(selectorExpression, selector.toLowerCase(), element, report, getExpressionMigrator());
                    setOSValue(osStore, selectorExpression, "value");
                }
            }
            if (watermark.getAttribute("object-store-ref") != null) {
                osStore.setAttribute("objectStore", watermark.getAttributeValue("object-store-ref"));
                osRetrieve.setAttribute("objectStore", watermark.getAttributeValue("object-store-ref"));
            }
            addElementAfter(osRetrieve, element);
            addElementToBottom(getContainerElement(element), osStore);
            watermark.detach();
            addOSModule();
        }
    } catch (Exception ex) {
        throw new MigrationStepException("Failed to migrate poll." + ex.getMessage() + ex.getStackTrace());
    }
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) AbstractOSMigrator(com.mulesoft.tools.migration.library.mule.steps.os.AbstractOSMigrator) ApplicationModelUtils.addChildNode(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addChildNode) WatermarkSelectorMigrator(com.mulesoft.tools.migration.library.tools.mel.WatermarkSelectorMigrator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ApplicationModelUtils.changeNodeName(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeNodeName) Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) XmlDslUtils.getCoreXPathSelector(com.mulesoft.tools.migration.step.util.XmlDslUtils.getCoreXPathSelector) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) XmlDslUtils.addElementToBottom(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementToBottom) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 17 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class AbstractAmqpEndpoint method migrateAmqpConfig.

public static String migrateAmqpConfig(Element object, MigrationReport report, Optional<Element> connector, ApplicationModel appModel) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "AmqpConfig");
    Optional<Element> config = appModel.getNodeOptional("*/*[(namespace-uri()='" + AMQP_NAMESPACE_URI + "' or namespace-uri()='" + AMQPS_NAMESPACE_URI + "') and local-name()='config' and @name='" + configName + "']");
    config.orElseGet(() -> {
        final Element amqpConfig = new Element("config", AMQP_NAMESPACE);
        amqpConfig.setAttribute("name", configName);
        connector.ifPresent(conn -> {
            addConnectionToConfig(amqpConfig, conn, appModel, report);
            if (hasAttribute(conn, "fallbackAddresses")) {
                report.report("amqp.fallbackAddresses", conn, amqpConfig);
            }
            if (hasAttribute(conn, "default-return-endpoint-ref")) {
                report.report("amqp.returnListener", conn, amqpConfig);
            }
            if (mustAddConsumerConfig(conn)) {
                addConsumerConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (mustAddPublisherConfig(conn)) {
                addPublisherConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (mustAddQoSConfig(conn)) {
                addQoSConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (hasAttribute(conn, "activeDeclarationsOnly")) {
                String fallbackQueueActionValue = Boolean.toString(!parseBoolean(conn.getAttribute("activeDeclarationsOnly").getValue()));
                amqpConfig.setAttribute("createFallbackQueue", fallbackQueueActionValue);
                amqpConfig.setAttribute("createFallbackExchange", fallbackQueueActionValue);
                report.report("activeDeclarationsOnly", conn, amqpConfig);
            }
        });
        addTopLevelElement(amqpConfig, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return amqpConfig;
    });
    return configName;
}
Also used : DeliveryModeAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.DeliveryModeAttributeMapper) Optional.of(java.util.Optional.of) Set(java.util.Set) HashMap(java.util.HashMap) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) List(java.util.List) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) AckModeAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.AckModeAttributeMapper) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.amqp.AmqpConnector.XPATH_SELECTOR) SimpleAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.SimpleAttributeMapper) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Map(java.util.Map) XmlDslUtils.hasAttribute(com.mulesoft.tools.migration.step.util.XmlDslUtils.hasAttribute) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 18 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class AbstractMigrationTask method fetchAndProcessNodes.

private void fetchAndProcessNodes(MigrationReport report, ApplicationModelContribution s, List<Element> alreadyProcessed) {
    AtomicInteger processedElements = new AtomicInteger(0);
    List<Element> nodes = applicationModel.getNodes(s.getAppliedTo());
    nodes.stream().filter(n -> !alreadyProcessed.contains(n)).forEach(n -> {
        try {
            processedElements.incrementAndGet();
            s.execute(n, report);
        } catch (Exception e) {
            throw new MigrationStepException("Task execution exception (" + e.getMessage() + ") migrating node:" + lineSeparator() + outp.outputString(n), e);
        }
    });
    alreadyProcessed.addAll(nodes);
    nodes.removeAll(applicationModel.getNodes(s.getAppliedTo()));
    if (!nodes.isEmpty()) {
        // This recursive calls is here so if any task adds nodes to the config that would be processed by this task, those are
        // processed.
        // Also, this is recursive rather than iterative so in the case of a bug, we get a StackOverflow rather than an infinite
        // loop.
        fetchAndProcessNodes(report, s, alreadyProcessed);
    }
    report.addProcessedElements(processedElements.get());
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Preconditions.checkState(com.google.common.base.Preconditions.checkState) XMLOutputter(org.jdom2.output.XMLOutputter) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) List(java.util.List) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ReportingStep(com.mulesoft.tools.migration.step.ReportingStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) Element(org.jdom2.Element) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException)

Example 19 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class SmtpOutboundEndpoint method migrateSmtpConfig.

public Element migrateSmtpConfig(Element object, MigrationReport report, Optional<Element> connector) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "SmtpConfig");
    Optional<Element> config = getApplicationModel().getNodeOptional("*/*[namespace-uri() = '" + EMAIL_NAMESPACE.getURI() + "' and local-name() = 'smtp-config' and @name='" + configName + "']");
    return config.orElseGet(() -> {
        final Element smtpCfg = new Element("smtp-config", EMAIL_NAMESPACE);
        smtpCfg.setAttribute("name", configName);
        Element connection = createConnection();
        smtpCfg.addContent(connection);
        addTopLevelElement(smtpCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return smtpCfg;
    });
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) IOException(java.io.IOException) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) DataWeaveHelper.getMigrationScriptFolder(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.getMigrationScriptFolder) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Text(org.jdom2.Text) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) DataWeaveHelper.library(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.library) Attribute(org.jdom2.Attribute) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) XmlDslUtils.migrateReconnection(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnection) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 20 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class RequestReply method migrateJmsRequestReply.

protected void migrateJmsRequestReply(Element object, MigrationReport report, final Element request, final Element reply, final Optional<Element> requestConnector) {
    getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
    request.setNamespace(JMS_NAMESPACE);
    request.setName("publish-consume");
    String jmsConfig = migrateJmsConfig(request, report, requestConnector, getApplicationModel());
    migrateOutboundJmsEndpoint(request, report, requestConnector, jmsConfig, getApplicationModel());
    request.detach();
    addElementAfter(request, object);
    object.detach();
    final Element replyTo = request.getChild("message", JMS_NAMESPACE).getChild("reply-to", JMS_NAMESPACE);
    String destination = processAddress(reply, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            replyTo.setAttribute("destinationType", "TOPIC");
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (reply.getAttributeValue("queue") != null) {
            return reply.getAttributeValue("queue");
        } else {
            replyTo.setAttribute("destinationType", "TOPIC");
            return reply.getAttributeValue("topic");
        }
    });
    replyTo.setAttribute("destination", destination);
    if (object.getAttribute("timeout") != null) {
        request.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("timeout")));
    }
    migrateOutboundEndpointStructure(getApplicationModel(), request, report, true);
    extractInboundChildren(reply, request.getParentElement().indexOf(request) + 2, request.getParentElement(), getApplicationModel());
    addAttributesToInboundProperties(request, getApplicationModel(), report);
}
Also used : AbstractVmEndpoint.resolveVmConector(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector) AbstractVmEndpoint.migrateVmConfig(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig) JmsOutboundEndpoint.migrateOutboundJmsEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint) VM_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE) AbstractGlobalEndpointMigratorStep.copyAttributes(com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Content(org.jdom2.Content) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) AbstractJmsEndpoint.resolveJmsConnector(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) VmOutboundEndpoint.migrateOutboundVmEndpoint(com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateOutboundVmEndpoint) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) JMS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE) Optional(java.util.Optional) AbstractVmEndpoint.getVmConfigName(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) AbstractJmsEndpoint.addAttributesToInboundProperties(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties) TransportsUtils.extractInboundChildren(com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) AbstractJmsEndpoint.migrateJmsConfig(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig) Element(org.jdom2.Element) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Aggregations

MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)33 Element (org.jdom2.Element)28 Optional (java.util.Optional)16 Namespace (org.jdom2.Namespace)16 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)13 List (java.util.List)13 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)12 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)12 Attribute (org.jdom2.Attribute)12 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)11 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)11 TransportsUtils.processAddress (com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress)10 XmlDslUtils.copyAttributeIfPresent (com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent)9 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)8 Collectors.toList (java.util.stream.Collectors.toList)8 XmlDslUtils.addTopLevelElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)6 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)6 StringUtils (org.apache.commons.lang3.StringUtils)6