blob: 0e006af5e0c286c16ba986be9b007feffe4c311c [file] [log] [blame]
package org.eclipse.papyrus.designer.components.modellibs.zmq.iconfigurators;
import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.designer.deployment.tools.AllocUtils;
import org.eclipse.papyrus.designer.deployment.tools.DepPlanUtils;
import org.eclipse.papyrus.designer.deployment.tools.DepUtils;
import org.eclipse.papyrus.designer.transformation.base.utils.ElementUtils;
import org.eclipse.papyrus.designer.transformation.base.utils.TransformationRTException;
import org.eclipse.papyrus.designer.transformation.extensions.IInstanceConfigurator;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Slot;
import org.eclipse.uml2.uml.UMLPackage;
public class ZMQAMI_SRConfigurator implements IInstanceConfigurator {
private static final String PORT_NUMBER = "portNumber"; //$NON-NLS-1$
private static final String IP_ADDRESS = "ipAddress"; //$NON-NLS-1$
public static final String tcpConfigName = "svTcpConfig"; //$NON-NLS-1$
public static final String tcpConfigLBName = "tcpipConfig";
public static final String roleConfigName = "roles";
public static final String ROLE = "roleValue";
public static final String FILTER = "filter";
public static final String nonFuncConfigName = "srConfigInfos";
public static final String TIMEOUT = "timeout";
public static final String RETRY_TIME = "retry_time";
public static final String MAX_REPLY_SIZE = "max_reply_size";
public static final String USE_RELIABLE = "use_reliable";
public static final String multiSvConfigName = "tcpConfigMultiSv";
enum ComponentRole {
CLIENT, BROKER, WORKER, SUBSCRIBER, PUBLISHER, CLIENT_AMICallback, SERVER_AMICallback, PUSH, PULL, CLIENT_SIMPLE, PUSH_PROD, PUSH_CONS, PULL_CONS, MULTICONN_CLIENT
};
@Override
public void configureInstance(InstanceSpecification instance, Property componentPart, InstanceSpecification parentInstance) {
Classifier socketRuntime = DepUtils.getClassifier(instance);
if (socketRuntime != null) {
Package cdp = instance.getNearestPackage();
EList<InstanceSpecification> allAllocs = AllocUtils.getAllNodes(DepUtils.getInstances(cdp));
Property tcpConfigLB = socketRuntime.getAttribute(tcpConfigLBName, null);
if (tcpConfigLB == null) {
throw new TransformationRTException(String.format("Cannot find property %s in class AMISocketRuntime", tcpConfigName));
}
Property roleConfig = socketRuntime.getAttribute(roleConfigName, null);
if (roleConfig == null) {
throw new TransformationRTException(String.format("Cannot find property %s in class AMISocketRuntime", roleConfigName));
}
Property nonFuncConfig = socketRuntime.getAttribute(nonFuncConfigName, null);
if (nonFuncConfig == null) {
throw new TransformationRTException(String.format("Cannot find property %s in class AMISocketRuntime", nonFuncConfigName));
}
Property tcpMultiConfig = socketRuntime.getAttribute(multiSvConfigName, null);
if (tcpMultiConfig == null) {
throw new TransformationRTException(String.format("Cannot find property %s in class AMISocketRuntime", multiSvConfigName));
}
String insNonFuncConfigName = instance.getName() + "." + nonFuncConfigName;
InstanceSpecification isConfigNonFunc = null;
if (cdp.getPackagedElement(insNonFuncConfigName) == null) {
isConfigNonFunc = (InstanceSpecification) cdp.createPackagedElement(insNonFuncConfigName, UMLPackage.eINSTANCE.getInstanceSpecification());
Classifier configNonFuncCl = (Classifier) nonFuncConfig.getType();
isConfigNonFunc.getClassifiers().add(configNonFuncCl);
DepPlanUtils.createSlot(cdp, instance, isConfigNonFunc, nonFuncConfig);
Property propRetryTime = configNonFuncCl.getAttribute(RETRY_TIME, null);
Property propTimeOut = configNonFuncCl.getAttribute(TIMEOUT, null);
Property propMaxReplySize = configNonFuncCl.getAttribute(MAX_REPLY_SIZE, null);
Property propUseReliable = configNonFuncCl.getAttribute(USE_RELIABLE, null);
Slot slotRetryTime = DepUtils.getSlot(allAllocs.get(0), propRetryTime);
Slot slotTimeOut = DepUtils.getSlot(allAllocs.get(0), propTimeOut);
Slot slotMaxReplySize = DepUtils.getSlot(allAllocs.get(0), propMaxReplySize);
Slot slotUseReliable = DepUtils.getSlot(allAllocs.get(0), propUseReliable);
if ((slotMaxReplySize != null) && (slotTimeOut != null) && (slotMaxReplySize != null) && (slotUseReliable != null)) {
DepPlanUtils.configureProperty(isConfigNonFunc, propRetryTime, DepUtils.firstValue(slotRetryTime).integerValue());
DepPlanUtils.configureProperty(isConfigNonFunc, propTimeOut, DepUtils.firstValue(slotTimeOut).integerValue());
DepPlanUtils.configureProperty(isConfigNonFunc, propMaxReplySize, DepUtils.firstValue(slotMaxReplySize).integerValue());
DepPlanUtils.configureProperty(isConfigNonFunc, propUseReliable, DepUtils.firstValue(slotUseReliable).integerValue());
}
}
int i = 0;
for (InstanceSpecification alloc : allAllocs) {
// array configuration: create multiple slots for same defining
// feature
// DepPlanUtils.createDepPlan(cdp, composite, name)
// the configuration of arrays via slots is ambiguous. It is not
// clear which index of
// a defining feature is pointed to by a slot. Pragmatically, we
// add the index to the instance
// name.
String instMultiConfigName = instance.getName() + "." + multiSvConfigName + "[" + i + "]";
if (cdp.getPackagedElement(instMultiConfigName) == null) {
InstanceSpecification isMultiConfigTcp = (InstanceSpecification) cdp.createPackagedElement(instMultiConfigName, UMLPackage.eINSTANCE.getInstanceSpecification());
Classifier tcpMultiConfigCl = (Classifier) tcpMultiConfig.getType();
isMultiConfigTcp.getClassifiers().add(tcpMultiConfigCl);
DepPlanUtils.createSlot(cdp, instance, isMultiConfigTcp, tcpMultiConfig);
Property propIPaddress = tcpMultiConfigCl.getAttribute(IP_ADDRESS, null);
Property propPortNumber = tcpMultiConfigCl.getAttribute(PORT_NUMBER, null);
Slot slotIPaddress = DepUtils.getSlot(alloc, propIPaddress);
Slot slotPortNumber = DepUtils.getSlot(alloc, propPortNumber);
if (slotIPaddress != null && slotPortNumber != null) {
DepPlanUtils.configureProperty(isMultiConfigTcp, propIPaddress, ElementUtils.quoteString(DepUtils.firstValue(slotIPaddress).stringValue()));
DepPlanUtils.configureProperty(isMultiConfigTcp, propPortNumber, DepUtils.firstValue(slotPortNumber).integerValue());
}
}
String instNameRole = instance.getName() + "." + roleConfigName + "[" + i + "]"; //$NON-NLS-1$ //$NON-NLS-2$
if (cdp.getPackagedElement(instNameRole) == null) {
InstanceSpecification isConfig = (InstanceSpecification) cdp.createPackagedElement(instNameRole, UMLPackage.eINSTANCE.getInstanceSpecification());
Classifier roleConfigCl = (Classifier) roleConfig.getType();
isConfig.getClassifiers().add(roleConfigCl);
DepPlanUtils.createSlot(cdp, instance, isConfig, roleConfig);
Property propRoleValue = roleConfigCl.getAttribute(ROLE, null);
Slot slotRoleValue = DepUtils.getSlot(alloc, propRoleValue);
int roleValue = DepUtils.firstValue(slotRoleValue).integerValue();
DepPlanUtils.configureProperty(isConfig, propRoleValue, roleValue);
if (roleValue == ComponentRole.SUBSCRIBER.ordinal()) {
isConfigNonFunc = (InstanceSpecification) cdp.getPackagedElement(insNonFuncConfigName);
Classifier configNonFuncCl = (Classifier) nonFuncConfig.getType();
Property propFilter = configNonFuncCl.getAttribute(FILTER, null);
Slot slotFilter = DepUtils.getSlot(alloc, propFilter);
DepPlanUtils.configureProperty(isConfigNonFunc, propFilter, ElementUtils.quoteString(DepUtils.firstValue(slotFilter).stringValue()));
} else if (roleValue == ComponentRole.CLIENT.ordinal() || roleValue == ComponentRole.WORKER.ordinal()) {
String prefix = instance.getName() + "." + tcpConfigLBName + "[";
String indexConfig = roleValue == ComponentRole.CLIENT.ordinal() ? 0 + "]" : 1 + "]";
String instNameTcp = prefix + indexConfig;
if (cdp.getPackagedElement(instNameTcp) == null) {
InstanceSpecification isConfigTcp = (InstanceSpecification) cdp.createPackagedElement(instNameTcp, UMLPackage.eINSTANCE.getInstanceSpecification());
Classifier tcpConfigCl = (Classifier) tcpConfigLB.getType();
isConfigTcp.getClassifiers().add(tcpConfigCl);
DepPlanUtils.createSlot(cdp, instance, isConfigTcp, tcpConfigLB);
Property propIPaddress = tcpConfigCl.getAttribute(IP_ADDRESS, null);
Property propPortNumber = tcpConfigCl.getAttribute(PORT_NUMBER, null);
Slot slotIPaddress = DepUtils.getSlot(alloc, propIPaddress);
Slot slotPortNumber = DepUtils.getSlot(alloc, propPortNumber);
DepPlanUtils.configureProperty(isConfigTcp, propIPaddress, ElementUtils.quoteString(DepUtils.firstValue(slotIPaddress).stringValue()));
DepPlanUtils.configureProperty(isConfigTcp, propPortNumber, DepUtils.firstValue(slotPortNumber).integerValue());
}
} else if (roleValue == ComponentRole.PUSH_CONS.ordinal()) {
} else if (roleValue == ComponentRole.PULL_CONS.ordinal()) {
} else if (roleValue == ComponentRole.PUSH.ordinal()) {
} else if (roleValue == ComponentRole.PUSH.ordinal()) {
} else if (roleValue == ComponentRole.BROKER.ordinal()) {
/* do nothing */
} else {
// throw new TransformationRTException(
// String.format(
// "Value for %s in class AMISocketRuntime is not valid",
// ROLE));
}
}
i++;
}
}
}
}