From ed7e1c3dfe332abc67ed943717db2ee94406f95e Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Thu, 29 Jun 2017 19:30:00 +0300 Subject: [SDC] rebase code Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6 Signed-off-by: Tal Gitelman Signed-off-by: Michael Lando --- openecomp-be/lib/openecomp-migration-lib/pom.xml | 192 -------------- .../src/main/assembly/migration-lib-assembly.xml | 26 -- .../org/openecomp/sdc/migration/TestScript.java | 11 - .../sdc/migration/ToscaNamespaceMigration.java | 290 --------------------- .../src/main/resources/logback.xml | 280 -------------------- .../src/main/resources/openecomp-migration-lib.zip | Bin 36707747 -> 0 bytes 6 files changed, 799 deletions(-) delete mode 100644 openecomp-be/lib/openecomp-migration-lib/pom.xml delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml delete 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 deleted file mode 100644 index 7c33315fbc..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/pom.xml +++ /dev/null @@ -1,192 +0,0 @@ - - - 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.sdc.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/src/main/assembly/migration-lib-assembly.xml b/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml deleted file mode 100644 index 3cb9fc07b4..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - 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 deleted file mode 100644 index c6a23734e4..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 4fa0ab368a..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java +++ /dev/null @@ -1,290 +0,0 @@ -package org.openecomp.sdc.migration; - -import org.apache.commons.collections4.CollectionUtils; -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.ComponentDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; -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.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; -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.Objects; -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 final ComponentDao componentDao = - ComponentDaoFactory.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) { - - changeComponentNamePrefix(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 changeComponentNamePrefix(VspDetails vspDetails){ - Collection componentsList = - componentDao.list(new ComponentEntity(vspDetails.getId(), vspDetails.getVersion(), null)); - - if(CollectionUtils.isEmpty(componentsList)){ - printMessage("No component namespace migration was performed on vsp with id" + vspDetails - .getId() + " and version " + vspDetails.getVersion().toString() + " since it has no " + - "components"); - return; - } - - for(ComponentEntity component : componentsList){ - String compositionData = component.getCompositionData(); - - if(Objects.isNull(compositionData)){ - continue; - } - - ComponentData componentData = - JsonUtil.json2Object(compositionData, ComponentData.class); - componentData.setName(componentData.getName().replace("com.att.d2", "org.openecomp")); - component.setCompositionData(JsonUtil.object2Json(componentData)); - - componentDao.update(component); - } - - printMessage("Component namespace migration was performed on vsp with id" + vspDetails - .getId() + " and version " + vspDetails.getVersion().toString()); - } - - 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 deleted file mode 100644 index 5596881329..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - ${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 deleted file mode 100644 index 659a2381f7..0000000000 Binary files a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip and /dev/null differ -- cgit 1.2.3-korg