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());
}
}
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;
}
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());
}
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;
});
}
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);
}
Aggregations