Skip to content

Commit

Permalink
FUSETOOLS-2140 - add camel 2.18.1 support (#757)
Browse files Browse the repository at this point in the history
* FUSETOOLS-2140 - Update Catalog Model Generator for Camel 2.18

- New attributes has been added to the catalog in Camel 2.18
- some elements are using '&' character since 2.18 so need to escape
them in our Catalog

* FUSETOOLS-2140 - add 2.18.1 community camel support

a first draft for the plugin and the generator code for the catalog
model. we now have 2 types of catalogs (karaf and springboot)...THIS IS
STILL A WORK IN PROGRESS!

* FUSETOOLS-2140 - extended camel model to allow multiple catalog flavors

* added a routecontainer super class and it has RoutesElement and CamelContextElement as derived classes for now

also fixed a bug which prevented the addition of new routes to a camel
container (routes or camelContext)

* done requested changes by Aurelien's review

* fixed dirty editor problem

* fixed regression in previous commit

* added a temporary workaround to be able to use the SNAPSHOT of camel 2.18.1

* rebased with master

* upgraded to camel 2.18.1.fuse-000010

* improved teardown method for project templates integration tests

* fixed amq templates to work with 2.18

* improved teardown of IT

* minor code tweaks and added a new test for routes file IO

* added bool flag for xml optimization

* FUSETOOLS-2140 - fixed syntax error after rebase

* fixed problem with multiple call of the setInput of the properties pane

* adapted launch config for linux to fix missing deps

* added 2.18.1 plugin to feature.xml

* switched to community camel 2.18.1

* fixes problem that route attribute get filled on route container elements

* generalized the previous fix for all element kind attributes of routecontainers

* code cleanup

* fixed problem with camelContext params in pre 2.18.1 versions

* make tests fail if the camel designer fails to load

* added 2 missing deps for the templates integration tests

* fixed issue where properties view camel context element gets out of sync

* improved code to prevent NPE
  • Loading branch information
lhein committed Dec 16, 2016
1 parent b187d5a commit 7d2463e
Show file tree
Hide file tree
Showing 127 changed files with 35,258 additions and 679 deletions.
7 changes: 7 additions & 0 deletions core/features/org.fusesource.ide.core.feature/feature.xml
Expand Up @@ -170,4 +170,11 @@
version="0.0.0"
unpack="false"/>

<plugin
id="org.fusesource.ide.camel.model.service.v2_18_1"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;

import org.fusesource.ide.camel.model.service.core.catalog.CamelModel;
import org.fusesource.ide.camel.model.service.core.catalog.CamelModelFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.util.tracker.ServiceTracker;
Expand Down Expand Up @@ -52,8 +53,17 @@ private ICamelManagerService checkedGetService() throws CamelManagerException {
*/
@Override
public CamelModel getCamelModel() {
CamelModel cm = checkedGetService().getCamelModel();
return getCamelModel(CamelModelFactory.RUNTIME_PROVIDER_KARAF);
}

/* (non-Javadoc)
* @see org.fusesource.ide.camel.model.service.core.ICamelManagerService#getCamelModel(java.lang.String)
*/
@Override
public CamelModel getCamelModel(String runtimeProvider) {
CamelModel cm = checkedGetService().getCamelModel(runtimeProvider);
cm.setCamelVersion(this.serviceVersion);
cm.setRuntimeProvider(runtimeProvider);
return cm;
}

Expand Down
Expand Up @@ -23,9 +23,19 @@ public interface ICamelManagerService {
* creates and returns the camel model for a specific version
*
* @return the camel model
* @deprecated Please use getCamelModel(String runtimeProvider) in future!
*/
@Deprecated
CamelModel getCamelModel();

/**
* creates and returns the camel model for a specific version and runtime
*
* @param runtimeProvider the name of the runtime provider
* @return the camel model
*/
CamelModel getCamelModel(String runtimeProvider);

/**
* returns the schema provider
*
Expand Down
Expand Up @@ -22,6 +22,7 @@
public class CamelModel {

private String camelVersion;
private String runtimeProvider;

private ComponentModel componentModel;
private DataFormatModel dataformatModel;
Expand All @@ -40,8 +41,9 @@ public CamelModel() {
*
* @param camelVersion the camel version of the model
*/
public CamelModel(String camelVersion) {
public CamelModel(String camelVersion, String runtimeProvider) {
this.camelVersion = camelVersion;
this.runtimeProvider = runtimeProvider;
}

/**
Expand All @@ -58,6 +60,20 @@ public void setCamelVersion(String camelVersion) {
this.camelVersion = camelVersion;
}

/**
* @return the runtimeProvider
*/
public String getRuntimeProvider() {
return this.runtimeProvider;
}

/**
* @param runtimeProvider the runtimeProvider to set
*/
public void setRuntimeProvider(String runtimeProvider) {
this.runtimeProvider = runtimeProvider;
}

/**
* @param componentModel the componentModel to set
*/
Expand Down
Expand Up @@ -40,17 +40,21 @@ public class CamelModelFactory {
camelVersionToFuseBOMMapping.put("2.15.1.redhat-621084", "6.2.1.redhat-084");
camelVersionToFuseBOMMapping.put("2.15.1.redhat-621117", "6.2.1.redhat-117");
camelVersionToFuseBOMMapping.put("2.17.0.redhat-630187", "6.3.0.redhat-187");
camelVersionToFuseBOMMapping.put("2.17.3", "6.3.0.redhat-187");
camelVersionToFuseBOMMapping.put("2.17.3", "6.3.0.redhat-187");
camelVersionToFuseBOMMapping.put("2.18.1", "6.3.0.redhat-187");
}
private static final String LATEST_BOM_VERSION = "6.3.0.redhat-187";

private static HashMap<String, CamelModel> supportedCamelModels;

private static HashMap<String, Map<String, CamelModel>> supportedCamelModels;

public static final String RUNTIME_PROVIDER_KARAF = "karaf";
public static final String RUNTIME_PROVIDER_SPRINGBOOT = "springboot";

/**
* initializes all available models for the connectors group of the camel editor palette
*/
public static void initializeModels() {
supportedCamelModels = new HashMap<String, CamelModel>();
supportedCamelModels = new HashMap<>();

String[] versions = CamelServiceManagerUtil.getAvailableVersions();
for (String version : versions) {
Expand All @@ -64,7 +68,7 @@ public static void initializeModels() {
* @param mockedSupportedCamelModels
*/
@Deprecated
public static void initializeModels(HashMap<String, CamelModel> mockedSupportedCamelModels) {
public static void initializeModels(HashMap<String, Map<String, CamelModel>> mockedSupportedCamelModels) {
supportedCamelModels = mockedSupportedCamelModels;
}

Expand All @@ -85,25 +89,46 @@ public static List<String> getSupportedCamelVersions() {
*
* @param camelVersion
* @return
* @deprecated please use getModelForVersion(String camelVersion, String runtimeProvider) in future!
*/
@Deprecated
public static CamelModel getModelForVersion(String camelVersion) {
CamelModel cm = supportedCamelModels.get(camelVersion);
return getModelForVersion(camelVersion, RUNTIME_PROVIDER_KARAF);
}

/**
* returns the model for a given camel version or null if not supported
*
* @param camelVersion
* @param runtimeProvider
* @return
*/
public static CamelModel getModelForVersion(String camelVersion, String runtimeProvider) {
Map<String, CamelModel> modelMap = supportedCamelModels.get(camelVersion);
CamelModel cm = null;
if (modelMap != null) {
cm = modelMap.get(runtimeProvider);
} else {
modelMap = new HashMap<>();
}

if (!supportedCamelModels.containsKey(camelVersion)) {
// seems user wants a version we don't have - look for compatible
// alternative supported version of camel
String alternateVersion = getCompatibleCamelVersion(camelVersion);
CamelModelServiceCoreActivator.pluginLog().logWarning("Selected Camel version " + camelVersion + " is not directly supported. Using alternative version: " + alternateVersion);
cm = supportedCamelModels.get(alternateVersion);
cm = supportedCamelModels.get(alternateVersion).get(runtimeProvider);
}

if (cm == null) {
// not initialized yet
ICamelManagerService svc = CamelServiceManagerUtil.getManagerService(camelVersion);
if (svc != null) {
cm = svc.getCamelModel();
cm = svc.getCamelModel(runtimeProvider);
cm.setCamelVersion(camelVersion);
supportedCamelModels.put(camelVersion, cm);
cm.setRuntimeProvider(runtimeProvider);
modelMap.put(runtimeProvider, cm);
supportedCamelModels.put(camelVersion, modelMap);
}
}

Expand Down
Expand Up @@ -197,7 +197,7 @@ public void setTags(ArrayList<String> tags) {
*/
public boolean canHaveChildren() {
for (Parameter p : getParameters()) {
if (p.getType().equalsIgnoreCase("array") && p.getKind().equalsIgnoreCase("element") && getInput().equalsIgnoreCase("true")) return true;
if (p.getType().equalsIgnoreCase("array") && p.getKind().equalsIgnoreCase(AbstractCamelModelElement.NODE_KIND_ELEMENT) && getInput().equalsIgnoreCase("true")) return true;
}
return false;
}
Expand All @@ -211,7 +211,7 @@ public List<String> getAllowedChildrenNodeTypes() {
ArrayList<String> allowedNodeTypes = new ArrayList<String>();
if (canHaveChildren()) {
for (Parameter p : getParameters()) {
if (p.getType().equalsIgnoreCase("array") && p.getKind().equalsIgnoreCase("element") && p.getOneOf() != null) {
if (p.getType().equalsIgnoreCase("array") && p.getKind().equalsIgnoreCase(AbstractCamelModelElement.NODE_KIND_ELEMENT) && p.getOneOf() != null) {
String oneOfList = p.getOneOf();
String[] types = oneOfList.split(",");
for (String type : types) {
Expand Down
Expand Up @@ -40,10 +40,10 @@
*/
public abstract class AbstractCamelModelElement {

private static final String NODE_KIND_EXPRESSION = "expression";
private static final String NODE_KIND_ATTRIBUTE = "attribute";
private static final String NODE_KIND_ELEMENT = "element";
static final String URI_PARAMETER_KEY = "uri";
public static final String NODE_KIND_EXPRESSION = "expression";
public static final String NODE_KIND_ATTRIBUTE = "attribute";
public static final String NODE_KIND_ELEMENT = "element";
public static final String URI_PARAMETER_KEY = "uri";
public static final String ENDPOINT_TYPE_TO = "to";
public static final String ENDPOINT_TYPE_FROM = "from";
public static final String TOPIC_REMOVE_CAMEL_ELEMENT = "TOPIC_REMOVE_CAMEL_ELEMENT";
Expand All @@ -57,6 +57,7 @@ public abstract class AbstractCamelModelElement {
public static final String WIRETAP_NODE_NAME = "wireTap";
public static final String ROUTE_NODE_NAME = "route";
public static final String ID_ATTRIBUTE = "id";
public static final String ROUTE_ATTRIBUTE = "route";
public static final String DATA_FORMATS_NODE_NAME = "dataFormats";
public static final String ENDPOINT_NODE_NAME = "endpoint";
public static final String CAMEL_CONTEXT_NODE_NAME = "camelContext";
Expand Down Expand Up @@ -86,11 +87,14 @@ public abstract class AbstractCamelModelElement {
// the camel file
private CamelFile cf;

// the camel context
private CamelContextElement context;
// the camel route container
private CamelRouteContainerElement container;

private String name;
private String description;

// flag which controls if default values are removed from file or not
private static boolean optimizedXML = true;

/**
* creates a camel node using the xml node
Expand Down Expand Up @@ -140,6 +144,23 @@ protected AbstractCamelModelElement(AbstractCamelModelElement parent, Node under
}
}

/**
* @return the optimizedXML
*/
public static boolean useOptimizedXML() {
return optimizedXML;
}

/**
* @param optimizedXML the optimizedXML to set
*/
public static void setOptimizedXML(boolean optimizedXML) {
AbstractCamelModelElement.optimizedXML = optimizedXML;
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return getDisplayText();
Expand Down Expand Up @@ -698,6 +719,13 @@ public void setParameter(String name, Object value) {
setParameter(name, value, false);
}

private boolean shouldIgnoreParameter(String name) {
return this instanceof CamelRouteContainerElement &&
getUnderlyingMetaModelObject() != null &&
getUnderlyingMetaModelObject().getParameter(name) != null &&
NODE_KIND_ELEMENT.equalsIgnoreCase(getUnderlyingMetaModelObject().getParameter(name).getKind());
}

/**
* sets the parameter with the given name to the given value. If the
* parameter doesn't exist it will be created
Expand All @@ -708,6 +736,11 @@ public void setParameter(String name, Object value) {
* if true params are written regardless if changed or not
*/
protected void setParameter(String name, Object value, boolean overrideChangeCheck) {

if (shouldIgnoreParameter(name)) {
return;
}

Object oldValue = this.parameters.get(name);

if (!overrideChangeCheck) {
Expand All @@ -723,6 +756,10 @@ protected void setParameter(String name, Object value, boolean overrideChangeChe
if (value != null && value.equals(oldValue)) {
return;
}
if (oldValue == null && value != null && getUnderlyingMetaModelObject() != null && getUnderlyingMetaModelObject().getParameter(name) != null && value.equals(getUnderlyingMetaModelObject().getParameter(name).getDefaultValue())) {
// this catches false updates from the properties pages setting default values automatically
return;
}
}

// save param in internal map
Expand Down Expand Up @@ -973,7 +1010,7 @@ private void updateElementDescription(String name, Object value, Element e) {
private void updateAttribute(String name, Object newValue, Object oldValue, Element e) {
String defaultValue = this.underlyingMetaModelObject != null
? this.underlyingMetaModelObject.getParameter(name).getDefaultValue() : null;
if (defaultValue != null && defaultValue.equals(getMappedValue(newValue))) {
if (defaultValue != null && defaultValue.equals(getMappedValue(newValue)) && useOptimizedXML()) {
// default value -> no need to explicitly set it -> delete
// existing
e.removeAttribute(name);
Expand Down Expand Up @@ -1537,15 +1574,20 @@ public String getIconName() {
if (u.startsWith("ref:")) {
// if its a ref we lookup what is the reference scheme
String refId = u.substring(u.indexOf(':') + 1);
AbstractCamelModelElement endpointRef = getCamelContext().getEndpointDefinitions().get(refId);
if (endpointRef != null) {
String refUri = (String) endpointRef.getParameter(URI_PARAMETER_KEY);
if (refUri != null && refUri.contains(":")) {
return refUri.substring(0, refUri.indexOf(':'));
} else {
// seems we have a broken ref
return ENDPOINT_NODE_NAME;
CamelRouteContainerElement container = getRouteContainer();
if (container instanceof CamelContextElement) {
AbstractCamelModelElement endpointRef = ((CamelContextElement)container).getEndpointDefinitions().get(refId);
if (endpointRef != null) {
String refUri = (String) endpointRef.getParameter(URI_PARAMETER_KEY);
if (refUri != null && refUri.contains(":")) {
return refUri.substring(0, refUri.indexOf(':'));
} else {
// seems we have a broken ref
return ENDPOINT_NODE_NAME;
}
}
} else {
CamelModelServiceCoreActivator.pluginLog().logWarning("ref: notation not supported for " + container.getNodeTypeId());
}
} else {
if (u.indexOf(':') != -1) {
Expand Down Expand Up @@ -1605,17 +1647,17 @@ public CamelFile getCamelFile() {
*
* @return
*/
public CamelContextElement getCamelContext() {
if (this.context == null) {
public CamelRouteContainerElement getRouteContainer() {
if (this.container == null) {
AbstractCamelModelElement tmp = this;
while (tmp.getParent() != null && !(tmp.getParent() instanceof CamelContextElement)) {
while (tmp.getParent() != null && !(tmp.getParent() instanceof CamelRouteContainerElement)) {
tmp = tmp.getParent();
}
if (tmp.getParent() != null && tmp.getParent() instanceof CamelContextElement) {
this.context = (CamelContextElement) tmp.getParent();
if (tmp.getParent() != null && tmp.getParent() instanceof CamelRouteContainerElement) {
this.container = (CamelRouteContainerElement) tmp.getParent();
}
}
return this.context;
return this.container;
}

/**
Expand All @@ -1626,7 +1668,7 @@ public CamelContextElement getCamelContext() {
public String getNewID() {
int i = 1;
String answer = String.format("_%s%d", getNodeTypeId(), i++);
while (!getCamelContext().isNewIDAvailable(answer)) {
while (!getRouteContainer().isNewIDAvailable(answer)) {
answer = String.format("_%s%d", getNodeTypeId(), i++);
}
return answer;
Expand All @@ -1643,7 +1685,7 @@ public boolean isIDUnique(String id) {
return false;
}

if (getCamelContext().findAllNodesWithId(id).size()>1) {
if (getRouteContainer().findAllNodesWithId(id).size()>1) {
return false;
}

Expand All @@ -1660,7 +1702,7 @@ public boolean isNewIDAvailable(String newId) {
if (newId == null || newId.trim().isEmpty()) {
return false;
}
return getCamelContext() == null || getCamelContext().findNode(newId) == null;
return getRouteContainer() == null || getRouteContainer().findNode(newId) == null;
}

/**
Expand Down

0 comments on commit 7d2463e

Please sign in to comment.