public boolean execute() { List<KMFContainer> metas = c.getTypeDefinition().select("deployUnits[]/filters[name=platform,value=java]"); if (metas.isEmpty()) { Log.error("No DeployUnit found for '" + c.getName() + ": " + c.getTypeDefinition().getName() + "/" + c.getTypeDefinition().getVersion() + "' that matches the 'java' platform"); return false; } Thread subThread = null; try { tg = new KevoreeThreadGroup("kev/" + c.path()); subThread = new Thread(tg, this); subThread.start(); subThread.join(); return resultSub; } catch (Throwable e) { if (subThread != null) { try { //subThread.stop(); //kill sub thread subThread.interrupt(); } catch (Throwable t) { //ignore killing thread } } Log.error("Could not add the instance {}:{}", c.getName(), c.getTypeDefinition().getName(), e); return false; } }
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars) throws KevScriptException { final List<Instance> instances = InstanceResolver.resolve(stmt.getChildren().get(0), model, ctxVars); for (final Instance i : instances) { i.setStarted(true); } } }
private String instance2fqn(Instance instance) { if (instance instanceof ContainerNode || instance instanceof Group || instance instanceof Channel) { return instance.getName() + ": " + instance.getTypeDefinition().getName() + "/" + instance.getTypeDefinition().getVersion(); } else { return ((NamedElement) instance.eContainer()).getName() + "." + instance.getName() + ": " + instance.getTypeDefinition().getName() + "/" + instance.getTypeDefinition().getVersion(); } } }
@Nullable @Override public FlexyClassLoader installTypeDefinition(Instance instance) { TypeDefinition td = instance.getTypeDefinition(); List<KMFContainer> filters = td.select("deployUnits[]/filters[name=platform,value=java]"); if (filters.size() > 1) { String filtersStr = ""; for (int i=0; i < filters.size(); i++) { filtersStr += filters.get(i).eContainer().path(); if (i < filters.size() - 1) { filtersStr += ", "; } } throw new RuntimeException("Instance " + instance.path() + " has " + filters.size() + " deployUnits ("+filtersStr+") that matches platform \"java\" (must only be one)"); } DeployUnit du = (DeployUnit) filters.get(0).eContainer(); return installDeployUnit(du); }
for (final Instance target : toChangeDico) { if (targetNodes == null) { if (target.getDictionary() == null) { target.setDictionary(factory.createDictionary()); Value dicValue = target.getDictionary().findValuesByID(propName); if (dicValue == null) { dicValue = factory.createValue(); if (target.getTypeDefinition().getDictionaryType() != null) { final DictionaryAttribute dicAtt = target.getTypeDefinition().getDictionaryType() .findAttributesByID(propName); if (dicAtt == null) { throw new KevScriptError( "Param does not exist in type " + target.getName() + " -> " + propName); } else { dicValue.setName(dicAtt.getName()); target.getDictionary().addValues(dicValue); if (target.findFragmentDictionaryByID(targetNode.getName()) == null) { final FragmentDictionary newDictionary = factory.createFragmentDictionary(); newDictionary.setName(targetNode.getName()); target.addFragmentDictionary(newDictionary); Value dicValue = target.findFragmentDictionaryByID(targetNode.getName()) .findValuesByID(propName); if (dicValue == null) { dicValue = factory.createValue(); if (target.getTypeDefinition().getDictionaryType() != null) {
public String toString() { String s = "StartStopInstance " + c.getName(); if (start) { s += " start"; } else { s += " stop"; } return s; }
@NotNull @Override public void injectDictionary(Instance instance, Object target, boolean defaultOnly) { if (instance.getTypeDefinition() == null || instance.getTypeDefinition().getDictionaryType() == null) { return; for (DictionaryAttribute att : instance.getTypeDefinition().getDictionaryType().getAttributes()) { String defValue = null; String value = null; if (att.getFragmentDependant()) { FragmentDictionary fdico = instance.findFragmentDictionaryByID(nodeName); if (fdico != null) { Value tempValue = fdico.findValuesByID(att.getName()); if (instance.getDictionary() != null) { Value tempValue = instance.getDictionary().findValuesByID(att.getName()); if (tempValue != null) { value = tempValue.getValue();
public void run() { try { FlexyClassLoader newKCL = ClassLoaderHelper.createInstanceClassLoader(c, nodeName, bs); Thread.currentThread().setContextClassLoader(newKCL); Thread.currentThread().setName("KevoreeAddInstance" + c.getName()); KInstanceWrapper newBeanKInstanceWrapper; if (c instanceof ContainerNode) { newBeanKInstanceWrapper = wrapperFactory.wrap(c, this/* nodeInstance is useless because launched as external process */, tg, bs, modelService); newBeanKInstanceWrapper.setKcl(newKCL); registry.register(c, newBeanKInstanceWrapper); } else { Object newBeanInstance = bs.createInstance(c, newKCL); newBeanKInstanceWrapper = wrapperFactory.wrap(c, newBeanInstance, tg, bs, modelService); newBeanKInstanceWrapper.setKcl(newKCL); registry.register(c, newBeanKInstanceWrapper); bs.injectDictionary(c, newBeanInstance, true); } newBeanKInstanceWrapper.create(); resultSub = true; Thread.currentThread().setContextClassLoader(null); Log.info("Add instance {}", c.path()); } catch(Throwable e) { Log.error("Error while adding instance {}", e, c.getName()); resultSub = false; } }
i.setStarted(true); Dictionary dictionary = factory.createDictionary().withGenerated_KMF_ID("0.0"); DictionaryType dictionaryType = i.getTypeDefinition().getDictionaryType(); if (dictionaryType != null) { for (DictionaryAttribute attr : dictionaryType.getAttributes()) { i.setDictionary(dictionary); } else {
private void debug(Value value) { Instance instance = (Instance) value.eContainer().eContainer(); DictionaryAttribute attr = instance.getTypeDefinition().getDictionaryType().findAttributesByID(value.getName()); if (attr.getFragmentDependant()) { Log.debug("Update param for {}.{}/{} = '{}'", instance.getName(), value.getName(), ((NamedElement) value.eContainer()).getName(), value.getValue()); } else { Log.debug("Update param for {}.{} = '{}'", instance.getName(), value.getName(), value.getValue()); } }
private DeployUnit getJavaDeployUnit(Instance instance) { TypeDefinition tdef = instance.getTypeDefinition(); if (tdef != null) { return tdef.getDeployUnits().stream().filter(du -> { Value filter = du.findFiltersByID("platform"); return filter != null && filter.getValue() != null && filter.getValue().equals("java"); }).findFirst().orElse(null); } return null; }
if (getModelElement().getDictionary() != null) { Value jvmArgsAttribute = getModelElement().getDictionary().findValuesByID("jvmArgs"); if (jvmArgsAttribute != null) { jvmArgs = jvmArgsAttribute.toString(); tempFile = File.createTempFile("bootModel" + getModelElement().getName(), ".json"); FileOutputStream tempIO = new FileOutputStream(tempFile); modelSaver.serializeToStream(tmodel, tempIO); execArray.add("-Dnode.name=" + getModelElement().getName()); execArray.add("org.kevoree.platform.standalone.App"); readerOUTthread = new Thread(new Reader(process.getInputStream(), getModelElement().getName(), false)); readerERRthread = new Thread(new Reader(process.getErrorStream(), getModelElement().getName(), true)); readerOUTthread.start(); readerERRthread.start();
if (currentModelElement.getStarted() == true && targetModelElement.getStarted() == true) { TupleObjPrim stopIns = new TupleObjPrim(modelElement, AdaptationType.StopInstance); if (!elementAlreadyProcessed.containsKey(stopIns.getKey())) { if (targetModelElement.getDictionary() != null) { for (Value val : targetModelElement.getDictionary().getValues()) { TupleObjPrim updateVal = new TupleObjPrim(val, AdaptationType.UpdateDictionaryInstance); if (!elementAlreadyProcessed.containsKey(updateVal.getKey())) { if (currentModelElement.getStarted() == true && targetModelElement.getStarted() == true) { TupleObjPrim startTuple = new TupleObjPrim(modelElement, AdaptationType.StartInstance); if (!elementAlreadyProcessed.containsKey(startTuple.getKey())) { if (modelElement instanceof org.kevoree.Value && modelElement.eContainer() instanceof Dictionary) { Instance instance = (Instance) modelElement.eContainer().eContainer(); if (instance != null && instance instanceof ContainerNode && instance.getName().equals(nodeName) && currentNode == null) {
public boolean execute() { try { Object ref = registry.lookup(c); if (ref instanceof KInstanceWrapper) { ((KInstanceWrapper) ref).destroy(); } registry.drop(c); Log.info("Remove instance {}", c.path()); return true; } catch (Exception e) { return false; } }
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars) throws Exception { final List<Instance> toRemove = InstanceResolver.resolve(stmt.getChildren().get(0), model, ctxVars); for (final Instance toDrop : toRemove) { if (toDrop instanceof ComponentInstance) { final ComponentInstance ci = (ComponentInstance) toDrop; for (final Port p : ci.getProvided()) { for (final MBinding mb : p.getBindings()) { mb.delete(); } } for (final Port p : ci.getRequired()) { for (final MBinding mb : p.getBindings()) { mb.delete(); } } } toDrop.delete(); } } }
for (final Instance target : toChangeDico) { if (targetNodes == null) { if (target.getDictionary() == null) { target.setDictionary(factory.createDictionary()); Value dicValue = target.getDictionary().findValuesByID(propName); if (dicValue == null) { dicValue = factory.createValue(); if (target.getTypeDefinition().getDictionaryType() != null) { final DictionaryAttribute dicAtt = target.getTypeDefinition().getDictionaryType() .findAttributesByID(propName); if (dicAtt == null) { throw new KevScriptException( "Param does not exist in type " + target.getName() + " -> " + propName); } else { dicValue.setName(dicAtt.getName()); target.getDictionary().addValues(dicValue); if (target.findFragmentDictionaryByID(targetNode.getName()) == null) { final FragmentDictionary newDictionary = factory.createFragmentDictionary(); newDictionary.setName(targetNode.getName()); target.addFragmentDictionary(newDictionary); Value dicValue = target.findFragmentDictionaryByID(targetNode.getName()) .findValuesByID(propName); if (dicValue == null) { dicValue = factory.createValue(); if (target.getTypeDefinition().getDictionaryType() != null) {
public String toString() { return "AddInstance " + c.getName(); } }
@Override public synchronized Object createInstance(final Instance instance, final ClassLoader classLoader) throws KevoreeCoreException { final DeployUnit du = getJavaDeployUnit(instance); try { final String mainClassName = searchMainClassName(instance); final Class clazz = classLoader.loadClass(mainClassName); final Object newInstance = clazz.newInstance(); final InstanceContext instanceContext = new InstanceContext(instance.path(), core.getNodeName(), instance.getName()); injector.register(Context.class, instanceContext); injector.register(ModelService.class, new ContextAwareModelServiceAdapter(core, instance.path())); // TODO there should be a GroupContext also that gives attached nodes etc.. injector.register(ChannelContext.class, new ChannelContextImpl(instanceContext)); injector.inject(newInstance); return newInstance; } catch (NoClassDefFoundError e) { throw new KevoreeCoreException("@KevoreeInject failed (is " + du.getName() + ":" + du.getVersion() + ":"+du.getHashcode().substring(0, 6)+" up-to-date?)", e); } catch (Throwable e) { throw new KevoreeCoreException("Unable to create instance " + instance.getName(), e); } }
i.setStarted(true); Dictionary dictionary = factory.createDictionary().withGenerated_KMF_ID("0.0"); DictionaryType dictionaryType = i.getTypeDefinition().getDictionaryType(); if (dictionaryType != null) { for (DictionaryAttribute attr : dictionaryType.getAttributes()) { i.setDictionary(dictionary); } else {
@Override public ClassLoader installTypeDefinition(Instance instance) throws KevoreeCoreException { TypeDefinition td = instance.getTypeDefinition(); DeployUnit du = validateFilters(instance, td.select("deployUnits[]/filters[name=platform,value=java]")); return installDeployUnit(du); }