/** * Create jar path with the given package version * * <p>appsDir/packageName_version.jar * * @param isJar * @param installedPackage * @return */ public static String getPackageFileName(PackageVersion version, boolean isJar) { StringBuilder s = new StringBuilder(); s.append(version.getPackaze().getPackageNamespace()); s.append(VERSION_SEPERATOR); s.append(version.getNumber()); if (isJar) { s.append(".jar"); } else { s.append(".data"); } return s.toString(); }
private static void prepareJAR(PackageVersion version, List<Instance> instances) { List<CompiledJavaClass> classes = new ArrayList<>(); List<Identity> identities = new ArrayList<>(); List<Translation> translations = new ArrayList<>(); for (Instance i : instances) { if (i instanceof CompiledJavaClass) { classes.add((CompiledJavaClass) i); } else if (i instanceof Identity) { identities.add((Identity) i); } else if (i instanceof Translation) { translations.add((Translation) i); } } LOG.info("Preparing JAR for package '" + version); String jarName = JarUtils.getPackagePath(version, true); try { // Prepare jar for this package version File file = new File(jarName); JarUtils.prepareJar( file, classes, identities, translations, version.getPackaze().getPackageNamespace()); } catch (Exception e) { LOG.info("Package Jar not prepared for " + jarName); throw new RuntimeException(e); } }
public static void updatePackageJar(PackageVersion version) { InvocationContext context = InvocationContext.get(); DataStore store = context.getDataStore(); int actualId = UploadingPackage.getActualId(); // Getting all members of this package except UploadedPackageMember List<Instance> instances = store.getAllPackageMembers(actualId); // Load all UploadedPackageMembers Set<Long> existedMembers = store.getUploadedComponentIds(actualId, context.getOrganizationId()); // Newly added members List<Instance> notExisted = instances .stream() .filter(i -> !existedMembers.contains(i.getId())) .collect(Collectors.toList()); List<UploadedPackageMember> newMembers = createUploadPackageMembers(notExisted, version); context.getDatabase().upsert(newMembers, DMLOperationType.THROW_ERRORS); prepareJAR(version, instances); prepatePackageData(version, instances); store.updateInstalledPackageLastUpdate(version.getId()); }
private static UploadedPackageMember createUploadedMembership( Instance component, PackageMember member, PackageVersion version) { // Create Uploaded Package Membership with cloned component UploadedPackageMember uploadMembership = AModelType.newInstanceOfType(SO.UPLOADED_PACKAGE_MEMBER); uploadMembership.setPackaze(version.getPackaze()); uploadMembership.setPackageVersion(version); uploadMembership.setComponent(component); uploadMembership.setPackageMember(member); return uploadMembership; }
private static void prepatePackageData(PackageVersion version, List<Instance> members) { LOG.info("Preparing Package Data file for package '" + version); String jarName = JarUtils.getPackagePath(version, false); // Prepare jar for this package version DataStore dataStore = InvocationContext.get().getDataStore(); try (GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(jarName))) { Kryo kryo = new Kryo(); Output output = new Output(out); // Write Package Members List<Instance> collect = members.stream().collect(Collectors.toList()); long id = version.getId(); SerializationUtil.writeInstances(kryo, output, collect); // Write QueryPlans List<ReplicationSQLQueryPlan> qPlans = dataStore.getAllQueryPlansByPackageVersion(id); output.writeInt(qPlans.size()); qPlans.forEach(m -> m.write(kryo, output)); // Write ModelHierarchyInfos List<ModelHierarchyInfo> mHierarchies = dataStore.getAllModelHierachyInfoByPackageVersion(id); output.writeInt(mHierarchies.size()); mHierarchies.forEach( m -> { output.writeInt(m.getParent()); output.writeInt(m.getSubModel()); }); // Write ClassHierarchy infos List<ClassHierarchyInfo> clsHierarchies = dataStore.getAllClassHierachyInfoByPackageVersion(id); output.writeInt(clsHierarchies.size()); clsHierarchies.forEach( m -> { output.writeString(m.getCls()); output.writeString(m.getSubClass()); }); output.close(); } catch (Exception e) { LOG.info("Package Data not prepared for " + jarName); throw new RuntimeException(e); } }