From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- openecomp-be/lib/openecomp-migration-lib/pom.xml | 192 ++++++++++++++ .../openecomp-migration-lib/pom.xml.versionsBackup | 151 +++++++++++ .../src/main/assembly/migration-lib-assembly.xml | 26 ++ .../org/openecomp/sdc/migration/TestScript.java | 11 + .../sdc/migration/ToscaNamespaceMigration.java | 247 ++++++++++++++++++ .../src/main/resources/logback.xml | 280 +++++++++++++++++++++ .../src/main/resources/openecomp-migration-lib.zip | Bin 0 -> 36737135 bytes 7 files changed, 907 insertions(+) create mode 100644 openecomp-be/lib/openecomp-migration-lib/pom.xml create mode 100644 openecomp-be/lib/openecomp-migration-lib/pom.xml.versionsBackup create mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml create mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java create mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java create mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml create mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip (limited to 'openecomp-be/lib/openecomp-migration-lib') diff --git a/openecomp-be/lib/openecomp-migration-lib/pom.xml b/openecomp-be/lib/openecomp-migration-lib/pom.xml new file mode 100644 index 0000000000..01603fc5e7 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/pom.xml @@ -0,0 +1,192 @@ + + + 4.0.0 + + openecomp-migration-lib + openecomp-migration-lib + + + org.openecomp.sdc + openecomp-sdc-lib + 1.1.0-SNAPSHOT + .. + + + + 2.4.7 + 2.7.7 + + + + + org.openecomp.sdc + openecomp-sdc-vendor-software-product-manager + ${project.version} + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + + org.openecomp.sdc.common + openecomp-configuration-management-core + ${openecomp.sdc.common.version} + runtime + + + org.slf4j + slf4j-log4j12 + + + + + + org.codehaus.janino + janino + ${janino.version} + + + + org.openecomp.core + openecomp-zusammen-core + ${project.version} + + + + org.codehaus.janino + commons-compiler + 3.0.6 + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + install + + copy-dependencies + + + ${project.build.directory}/lib + false + false + true + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${mvn.jar.version} + + + package + + + + + + true + custom + lib/${artifact.artifactId}-${baseVersion}.${artifact.extension} + org.openecomp.sdc.migration.ToscaNamespaceMigration + + + lib/ + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + false + true + + + + + com.google.code.maven-replacer-plugin + maven-replacer-plugin + 1.3.5 + + + replace-for-migration + initialize + + replace + + + ../../tools/migration/1702_to_1707.sh + false + target + + + 1707.0.0-SNAPSHOT + ${project.version} + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + ant-test + package + + + + + + + run + + + + + + + + + diff --git a/openecomp-be/lib/openecomp-migration-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-migration-lib/pom.xml.versionsBackup new file mode 100644 index 0000000000..bca0cd32a3 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/pom.xml.versionsBackup @@ -0,0 +1,151 @@ + + + 4.0.0 + + + + 2.4.7 + 2.7.7 + + + + + + org.openecomp.sdc + openecomp-sdc-vendor-software-product-manager + 1.0-SNAPSHOT + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + + org.openecomp.sdc.common + openecomp-configuration-management-core + 1707.0.0-SNAPSHOT + runtime + + + org.slf4j + slf4j-log4j12 + + + + + + org.codehaus.janino + janino + ${janino.version} + + + + org.codehaus.janino + commons-compiler + 3.0.6 + + + + + + org.openecomp.sdc + openecomp-sdc-lib + 1.0-SNAPSHOT + + + + openecomp-migration-lib + openecomp-migration-lib + 1.0-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + install + + copy-dependencies + + + ${project.build.directory}/lib + false + false + true + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + + + + + true + lib/ + org.openecomp.sdc.migration.ToscaNamespaceMigration + + + lib/ + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + ant-test + package + + + + + + + run + + + + + + maven-assembly-plugin + + + Generate assembly + install + + single + + + + + + ${basedir}/src/main/assembly/migration-lib-assembly.xml + + openecomp-migration-lib + + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml b/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml new file mode 100644 index 0000000000..3cb9fc07b4 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml @@ -0,0 +1,26 @@ + + + zip + + + false + + + + ${basedir}/target + + openecomp-migration-lib*.jar + 1702_to_1707.sh + + / + 0755 + + + ${basedir}/target/lib + /lib + + + + diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java new file mode 100644 index 0000000000..c6a23734e4 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java @@ -0,0 +1,11 @@ +package org.openecomp.sdc.migration; + +/** + * Created by TALIO on 3/19/2017. + */ +public class TestScript { + + public static void main(String[] args){ + System.out.print("Test succeed!"); + } +} diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java new file mode 100644 index 0000000000..82ba1396c7 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java @@ -0,0 +1,247 @@ +package org.openecomp.sdc.migration; + +import org.apache.commons.io.IOUtils; +import org.openecomp.core.model.dao.EnrichedServiceModelDao; +import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.Old1610ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; + + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + + +/** + * Created by TALIO on 3/19/2017 + */ +public class ToscaNamespaceMigration { + + private static VendorSoftwareProductManager vendorSoftwareProductManager = + VspManagerFactory.getInstance().createInterface(); + private static OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager = + OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(); + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static ServiceModelDao serviceModelDao = + ServiceModelDaoFactory.getInstance().createInterface(); + private static EnrichedServiceModelDao + enrichedServiceModelDao = + EnrichedServiceModelDaoFactory.getInstance().createInterface(); + private static VendorSoftwareProductInfoDao vspInfoDao = + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static PackageInfoDao packageInfoDao = PackageInfoDaoFactory.getInstance() + .createInterface(); + private static Logger logger = LoggerFactory.getLogger(ToscaNamespaceMigration.class); + private static int status = 0; + + + public static void main(String[] args) { + CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); + + Collection vspList = vspInfoDao.list(new VspDetails()); + + List packagesList = + packageInfoDao.listByCategory(null, null); + + for (VspDetails vspInfo : vspList) { + printMessage("Performing migration on vsp " + vspInfo.getName() + " and version " + vspInfo + .getVersion().toString() + "\n"); + performMigration(vspInfo); + } + + System.exit(status); + } + + private static void performMigration(VspDetails vspDetails) { + try { + changeNamespaceInServiceTemplates(vspDetails); + } catch (Exception e) { + printMessage( + "Could not perform migration for service templates on vsp " + vspDetails.getName()); + status = -1; + } + + if (vspDetails.getVersion().isFinal()) { + changeNamespaceInPackage(vspDetails); + } + } + + private static void changeNamespaceInServiceTemplates(VspDetails vspDetails) throws IOException { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + ToscaServiceModel serviceModel; + ToscaServiceModel enrichedServiceModel; + + serviceModel = + serviceModelDao.getServiceModel(vspId, version); + enrichedServiceModel = + enrichedServiceModelDao.getServiceModel(vspId, version); + + printMessage("Working on vsp_service_template table in DB \n"); + changeNamespaceInServiceModel(serviceModel); + printMessage("Finished Working on vsp_service_template table in DB \n"); + + printMessage("Working on vsp_enriched_service_template table in DB \n"); + changeNamespaceInServiceModel(enrichedServiceModel); + printMessage("Finished Working on vsp_enriched_service_template table in DB \n"); + + serviceModelDao.storeServiceModel(vspId, version, serviceModel); + enrichedServiceModelDao.storeServiceModel(vspId, version, enrichedServiceModel); + } + + private static void changeNamespaceInServiceModel(ToscaServiceModel serviceModel) { + Map changedServiceTemplates = new HashMap<>(); + Map serviceTemplates = serviceModel.getServiceTemplates(); + + for (Map.Entry serviceTemplateEntry : serviceTemplates.entrySet()) { + printMessage( + "Changing namespace for Service Template " + serviceTemplateEntry.getKey() + "\n"); + + ServiceTemplate serviceTemplate = serviceTemplateEntry.getValue(); + String fileAsJson = JsonUtil.object2Json(serviceTemplate); + String replacedNamespace = fileAsJson.replace("org.openecomp.d2", "org.openecomp"); + ServiceTemplate newServiceTemplate; + try { + newServiceTemplate = + new ToscaExtensionYamlUtil().yamlToObject(replacedNamespace, ServiceTemplate.class); + } catch (Exception e) { + System.out.println("Found vsp with old-versioned tosca service template"); + Old1610ServiceTemplate oldServiceTemplate = + JsonUtil.json2Object(replacedNamespace, Old1610ServiceTemplate.class); + newServiceTemplate = mapOldSTToCurrentST(oldServiceTemplate); + + } + changedServiceTemplates.put( + serviceTemplateEntry.getKey(), newServiceTemplate); + } + + serviceModel.setServiceTemplates(changedServiceTemplates); + } + + private static org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate mapOldSTToCurrentST( + Old1610ServiceTemplate oldServiceTemplate) { + org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate + serviceTemplate = new org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate(); + + serviceTemplate.setArtifact_types(oldServiceTemplate.getArtifact_types()); + serviceTemplate.setCapability_types(oldServiceTemplate.getCapability_types()); + serviceTemplate.setData_types(oldServiceTemplate.getData_types()); + serviceTemplate.setDescription(oldServiceTemplate.getDescription()); + serviceTemplate.setGroup_types(oldServiceTemplate.getGroup_types()); + serviceTemplate.setInterface_types(oldServiceTemplate.getInterface_types()); + serviceTemplate.setMetadata(oldServiceTemplate.getMetadata()); + serviceTemplate.setNode_types(oldServiceTemplate.getNode_types()); + serviceTemplate.setPolicy_types(oldServiceTemplate.getPolicy_types()); + serviceTemplate.setRelationship_types(oldServiceTemplate.getRelationship_types()); + serviceTemplate.setTopology_template(oldServiceTemplate.getTopology_template()); + + List> imports = new ArrayList<>(); + for (Map.Entry importEntry : oldServiceTemplate.getImports().entrySet()) { + Map importMap = new HashMap<>(); + importMap.put(importEntry.getKey(), importEntry.getValue()); + imports.add(importMap); + } + serviceTemplate.setImports(imports); + + return serviceTemplate; + + } + + private static void changeNamespaceInPackage(VspDetails vspDetails) { + String vspId = vspDetails.getId(); + printMessage("Start updating CSAR file with new namespace in DB \n"); + + File translatedFile; + try { + translatedFile = + getTranslatedFile(vspId, vspDetails.getVersion()); + } catch (Exception e) { + printMessage("No translated file was found under vsp " + vspDetails.getName() + "\n"); + return; + } + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ZipOutputStream zos = new ZipOutputStream(baos); + ZipFile zipFile = new ZipFile(translatedFile)) { + Enumeration entries = zipFile.entries(); + + while (entries.hasMoreElements()) { + ZipEntry ze = entries.nextElement(); + InputStream zipEntryIs = zipFile.getInputStream(ze); + byte[] contentAsByte = IOUtils.toByteArray(zipEntryIs); + String fileContent = new String(contentAsByte); + + String replacedNamespace = fileContent.replace("org.openecomp.d2", "org.openecomp"); + + zos.putNextEntry(new ZipEntry(ze.getName())); + zos.write(replacedNamespace.getBytes()); + } + printMessage("Changed Tosca namesapce in package for vsp " + vspDetails.getName() + "\n"); + + + packageInfoDao.updateTranslatedContent( + vspId, vspDetails.getVersion(), ByteBuffer.wrap(baos.toByteArray())); + printMessage("Updated CSAR file with new namespace in DB \n"); + + } catch (Exception e) { + printMessage("Could not perform migration on csar"); + } + } + + private static void printMessage(String message) { + System.out.print(message); + logger.debug(message); + } + + private static File getTranslatedFile(String vspId, Version version) + throws IOException { + PackageInfo packageInfo = + packageInfoDao.get(new PackageInfo(vspId, version)); + ByteBuffer translatedFileBuffer = packageInfo == null ? null : packageInfo.getTranslatedFile(); + + File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP); + + FileOutputStream fos = new FileOutputStream(translatedFile); + fos.write(translatedFileBuffer.array()); + fos.close(); + + + return translatedFile; + } +} diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml new file mode 100644 index 0000000000..5596881329 --- /dev/null +++ b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml @@ -0,0 +1,280 @@ + + + + + + + + + + + + + + + + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log.%i + + 1 + 10 + + + + 20MB + + + ${default-log-pattern} + + + + + + + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log + + + + + + AUDIT_MARKER + + NEUTRAL + DENY + + + + + + TRANSACTION_MARKER + + NEUTRAL + DENY + + + + + INFO + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log.%i + + 1 + 10 + + + + 20MB + + + ${default-log-pattern} + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log + + + + + + + TRANSACTION_MARKER + + NEUTRAL + DENY + + + + + + + e.level.toInt() <= DEBUG.toInt() + + + DENY + NEUTRAL + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log.%i + + 1 + 10 + + + + 20MB + + + ${default-log-pattern} + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/migration_debug.log + + + + + + + TRANSACTION_MARKER + + NEUTRAL + DENY + + + + + + + e.level.toInt() <= DEBUG.toInt() + + + DENY + NEUTRAL + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log.%i + + 1 + 10 + + + + 20MB + + + ${asdc-debug-log-pattern} + + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log + + + + + + AUDIT_MARKER + + DENY + ACCEPT + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log.%i + + 1 + 10 + + + + 20MB + + + ${default-log-pattern} + + + + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log + + + + + + TRANSACTION_MARKER + + DENY + ACCEPT + + + + ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log.%i + + 1 + 10 + + + + 20MB + + + ${default-log-pattern} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip new file mode 100644 index 0000000000..7f141387c9 Binary files /dev/null and b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip differ -- cgit 1.2.3-korg