public String toString() { return "RemoveDeployUnit " + KModelHelper.fqnGroup(du) + "/" + du.getName() + "/" + du.getVersion() + "/" + du.getHashcode(); } }
private String searchMainClassName(final Instance instance) throws KevoreeCoreException { TypeDefinition td = instance.getTypeDefinition(); DeployUnit du = validateFilters(instance, td.select("deployUnits[]/filters[name=platform,value=java]")); String tag = "class:" + td.getName() + ":" + td.getVersion(); Value tdefClassName = du.findFiltersByID(tag); if (tdefClassName != null) { return tdefClassName.getValue(); } else { throw new RuntimeException("Cannot find meta-data \"" + tag + "\" in DeployUnit " + du.getHashcode() + "/" + du.getName() + "/" + du.getVersion()); } }
public static String fqnGroup(DeployUnit du) { StringBuilder buffer = new StringBuilder(); org.kevoree.Package pack = (org.kevoree.Package) du.eContainer(); while (pack != null) { buffer.insert(0, "."); buffer.insert(0, pack.getName()); if (pack.eContainer() != null && pack.eContainer() instanceof Package) { pack = (org.kevoree.Package) pack.eContainer(); } else { pack = null; } } return buffer.substring(0, buffer.length()-1); }
private Map<String, String> getDUVersions(List<DeployUnit> dus) { Map<String, String> versions = new HashMap<>(); dus.forEach(du -> { String platform = du.findFiltersByID("platform").getValue(); versions.put(platform, du.getVersion()); }); return versions; } }
@Override public ClassLoader installDeployUnit(DeployUnit du) throws KevoreeCoreException { Value kevVersion = du.findFiltersByID("kevoree_version"); if (kevVersion == null || kevVersion.getValue() == null) { throw new KevoreeCoreException("DeployUnit " + du.getName() + ":" + du.getVersion() + " is incompatible with current runtime v" + core.getFactory().getVersion()); } else if (!kevVersion.getValue().equals(core.getFactory().getVersion())) { throw new KevoreeCoreException("DeployUnit " + du.getName() + ":" + du.getVersion() + " targets v" + kevVersion.getValue() + " which is incompatible with current runtime v" + core.getFactory().getVersion()); .forEach((id, url) -> repos.add(new RemoteRepository.Builder(id, "default", url).build())); ClassLoader classLoader = this.classLoaders.get(du.getUrl()); Log.info("Resolving ............. {}", du.getUrl()); long before = System.currentTimeMillis(); PreorderNodeListGenerator nlg = resolver .resolve(du.getUrl(), repos); Log.info("Resolved in {}ms", (System.currentTimeMillis() - before)); .collect(Collectors.toList()).toArray(URL_ARRAY); Log.trace("ClassLoader content for {}:{}:", du.getName(), du.getVersion()); for (URL url : jars) { Log.trace(" - {}", url.toString()); this.classLoaders.put(du.getUrl(), classLoader); return classLoader; } catch (MavenResolverException e) { throw new KevoreeCoreException("Unable to resolve DeployUnit " + du.getName() + ":" + du.getVersion(), e);
private DeployUnit createDeployUnit() { DeployUnit du = factory.createDeployUnit(); du.setName(project.getArtifact().getArtifactId()); String hashcode = ModelBuilderHelper.createKey(namespace, project.getArtifactId(), project.getVersion(), null); du.setHashcode(hashcode); du.setVersion(project.getArtifact().getBaseVersion()); Value platform = factory.createValue(); platform.setName("platform"); platform.setValue("java"); du.addFilters(platform); Value kevoreeVersion = factory.createValue(); kevoreeVersion.setName("kevoree_version"); kevoreeVersion.setValue(factory.getVersion()); du.addFilters(kevoreeVersion); Value timestamp = factory.createValue(); timestamp.setName("timestamp"); timestamp.setValue(String.valueOf(System.currentTimeMillis())); du.addFilters(timestamp); // add repositories for (Repository repo : project.getRepositories()) { Value repoVal = factory.createValue(); repoVal.setName("repo_" + repo.getId()); repoVal.setValue(repo.getUrl()); du.addFilters(repoVal); } // set Maven groupId:artifactId:version du.setUrl(project.getArtifact().getGroupId() + ":" + du.getName() + ":" + du.getVersion()); return du; }
private void processDeployUnit(ContainerRoot model, List<KMFContainer> tdefs, DeployUnit du) throws MojoExecutionException { String platform = du.findFiltersByID("platform").getValue(); TypeDefinition tdef = (TypeDefinition) elem; getLog().info("Looking for DeployUnit " + du.getName() + "/" + du.getVersion() + "/" + platform + " in the registry..."); HttpResponse<RDeployUnit> duRes = client.getDu(namespace, tdef.getName(), Long.valueOf(tdef.getVersion()), du.getName(), du.getVersion(), platform); if (duRes.getStatus() == 200) { RDeployUnit regDu = duRes.getBody(); newDu.setName(du.getName()); newDu.setVersion(du.getVersion()); newDu.setPlatform("java"); newDu.setModel(duStr);
getLog().info("DeployUnit: " + du.getName() + ":" + du.getVersion()); getLog().info(""); du.addFilters(classFilter);
private boolean isInstallable(TypeDefinition tdef) { List<DeployUnit> dus = tdef.getDeployUnits(); for (DeployUnit du : dus) { Value platform = du.findFiltersByID("platform"); if (platform != null && platform.getValue().equals("java")) { return true; } } return false; }
throw new KevoreeDeployException("You are trying to start a NodeType that does not target this runtime version", e); } catch (KevoreeCoreException e) { throw new KevoreeDeployException("Unable to create instance " + node.getName() + ": " + node.getTypeDefinition().getName() + "/" + node.getTypeDefinition().getVersion() + "/" + node.getTypeDefinition().getDeployUnits().get(0).getVersion(), e);
tdef.addDeployUnits(du); Log.debug(" + {}:{}:{} ({})", regDu.getPlatform(), regDu.getName(), regDu.getVersion(), du.getHashcode());
public boolean execute() { FlexyClassLoader installedKCL = bs.get(du); if (installedKCL == null) { Log.error("DeployUnit not installed !! {}", du.path()); return false; } for (DeployUnit ldu : du.getRequiredLibs()) { FlexyClassLoader subresolved = bs.get(ldu); if (subresolved == null) { Log.error("DeployUnit not installed !! {}", ldu.path()); return false; } else { kcls.add(subresolved); } } for (FlexyClassLoader subKCL : kcls) { installedKCL.attachChild(subKCL); } return true; }
@Override public ClassLoader get(DeployUnit du) { return this.classLoaders.get(du.getUrl()); }
private Map<String, String> getRepositories(DeployUnit deployUnit) { Map<String, String> repositories = new HashMap<>(); // hacky way to treat Maven repositories as I don't want to change the Kevoree MM for (Value val : deployUnit.getFilters()) { if (val.getName().startsWith("repo_")) { repositories.put(val.getName().substring(5), val.getValue()); } } return repositories; }
DeployUnit du = duModel.getPackages().get(0).getDeployUnits().get(0); compare.merge(model, duModel).applyOn(model); tdef.addDeployUnits((DeployUnit) model.findByPath(du.path()));
private boolean checkDUS(TypeDefinition tdef, Map<String, Object> duVersions) { boolean satisfied = true; for (Map.Entry<String, Object> entry : duVersions.entrySet()) { boolean found = false; for (int i=0; i < tdef.getDeployUnits().size(); i++) { DeployUnit du = tdef.getDeployUnits().get(i); String p = du.findFiltersByID("platform").getValue(); if (p.equals(entry.getKey()) && du.getVersion().equals(entry.getValue().toString())) { found = true; break; } } if (!found) { satisfied = false; break; } } return satisfied; } }
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; }
@Override public FlexyClassLoader get(DeployUnit deployUnit) { return this.get("mvn:"+deployUnit.getUrl()); }
private ConfigurableMavenResolverSystem getResolver(DeployUnit deployUnit) { String offlineProp = System.getProperty("offline", "false"); boolean offline = Boolean.valueOf(offlineProp); ConfigurableMavenResolverSystem resolver = Maven .configureResolver() .useLegacyLocalRepo(true) .workOffline(offline); try { LogManager.getLogManager().readConfiguration(new FileInputStream(propFile)); } catch (IOException e) { throw new RuntimeException("Unable to read " + propFile.getAbsolutePath()); } // hacky way to treat Maven repositories as I don't want to change the Kevoree MM for (Value val : deployUnit.getFilters()) { if (val.getName().startsWith("repo_")) { try { resolver.withRemoteRepo(val.getName().substring(5), new URL(val.getValue()), "default"); } catch (MalformedURLException e) { throw new RuntimeException("Invalid repository URL: " + val.getValue()); } } } return resolver; }
public String toString() { return "AddDeployUnit " + KModelHelper.fqnGroup(du) + "/" + du.getName() + "/" + du.getVersion() + "/" + du.getHashcode(); }