summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/tools')
-rw-r--r--openecomp-be/tools/install/database/schemaTemplates/questionnaire/compute.ftl10
-rw-r--r--openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/EntitlementPoolConvertor.java7
-rw-r--r--openecomp-be/tools/migration/cassandra2zusammen.sh7
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java18
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java25
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java44
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java9
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java50
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java3
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java11
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java44
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml281
12 files changed, 164 insertions, 345 deletions
diff --git a/openecomp-be/tools/install/database/schemaTemplates/questionnaire/compute.ftl b/openecomp-be/tools/install/database/schemaTemplates/questionnaire/compute.ftl
index 3dc85cf192..748f4da23e 100644
--- a/openecomp-be/tools/install/database/schemaTemplates/questionnaire/compute.ftl
+++ b/openecomp-be/tools/install/database/schemaTemplates/questionnaire/compute.ftl
@@ -40,12 +40,12 @@
"memoryRAM": {
"type": "string",
"enum": [
- "1",
- "2",
- "4",
- "8"
+ "1 GB",
+ "2 GB",
+ "4 GB",
+ "8 GB"
],
- "default": "1"
+ "default": "1 GB"
}
},
"additionalProperties": false
diff --git a/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/EntitlementPoolConvertor.java b/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/EntitlementPoolConvertor.java
index c8037cecf4..86faf15837 100644
--- a/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/EntitlementPoolConvertor.java
+++ b/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/EntitlementPoolConvertor.java
@@ -77,13 +77,10 @@ public class EntitlementPoolConvertor {
info.setDescription(entitlementPool.getDescription());
info.addProperty("thresholdValue", entitlementPool.getThresholdValue());
info.addProperty("threshold_unit", entitlementPool.getThresholdUnit());
- info.addProperty("entitlement_metric", entitlementPool.getEntitlementMetric());
+ //info.addProperty("entitlement_metric", entitlementPool.getEntitlementMetric());
info.addProperty("increments", entitlementPool.getIncrements());
- info.addProperty("aggregation_func", entitlementPool.getAggregationFunction());
info.addProperty("operational_scope", entitlementPool.getOperationalScope());
- info.addProperty("EntitlementTime", entitlementPool.getTime());
- info.addProperty("manufacturerReferenceNumber",
- entitlementPool.getManufacturerReferenceNumber());
+
return info;
}
diff --git a/openecomp-be/tools/migration/cassandra2zusammen.sh b/openecomp-be/tools/migration/cassandra2zusammen.sh
index 6ef90ad3bf..99853b8336 100644
--- a/openecomp-be/tools/migration/cassandra2zusammen.sh
+++ b/openecomp-be/tools/migration/cassandra2zusammen.sh
@@ -9,7 +9,6 @@
# change exist package and service templates in db
-java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=/apps/jetty/base/be/config/catalog-be/configuration.yaml -jar openecomp-zusammen-migration-1.0-SNAPSHOT.jar org.openecomp.core.migration.MigrationMain
-
-STATUS="${?}"
-echo "${STATUS}"
+## Code removed but script is kept for future hook use ##
+##STATUS="${?}"
+##echo "${STATUS}"
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
index b92ba52000..685f70db98 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
@@ -18,6 +18,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import static java.nio.file.Files.createDirectories;
public class ExportDataCommand {
@@ -25,6 +29,8 @@ public class ExportDataCommand {
public static void exportData(SessionContext context, String filterItem) {
try {
+ Set<String> filteredItem = new HashSet<>();
+ filteredItem.add(filterItem);
ImportProperties.initParams();
CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
@@ -32,10 +38,10 @@ public class ExportDataCommand {
if (filterItem != null) {
filterItem = filterItem.replaceAll("\\r", "");
}
- new ItemHandler().createItemsData(context, filterItem);
- new VersionHandler().loadVersions(filterItem);
- new ElementHandler().loadElements(filterItem);
- zipPath(rootDir,filterItem);
+ new ItemHandler().createItemsData(context, filteredItem);
+ new VersionHandler().loadVersions(filteredItem);
+ new ElementHandler().loadElements(filteredItem);
+ zipPath(rootDir,filteredItem);
FileUtils.forceDelete(rootDir.toFile());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
@@ -43,12 +49,14 @@ public class ExportDataCommand {
}
}
- private static void zipPath(Path rootDir,String filterItem ) throws Exception{
+ private static void zipPath(Path rootDir,Set<String> filterItem ) throws Exception{
LocalDateTime date = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
String dateStr = date.format(formatter);
String zipFile = System.getProperty("user.home")+ File.separatorChar+"onboarding_import"+ dateStr + ".zip";
ZipUtils.createZip(zipFile, rootDir,filterItem);
+ logger.info("Exported file :" + zipFile);
+ System.out.println("Exported file :" + zipFile);
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
index ebce90fb4a..49eaaeaa76 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
@@ -10,6 +10,7 @@ import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
+import java.util.Set;
import static java.io.File.separator;
import static java.nio.file.Files.*;
@@ -22,15 +23,16 @@ public class ElementHandler {
public ElementHandler() {
}
- public void loadElements(String filteredItem) {
+ public void loadElements(Set<String> filteredItem) {
ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader();
- elementCassandraLoader.list().forEach(elementEntity -> handleElementEntity(elementEntity,filteredItem));
+ elementCassandraLoader.list().forEach(elementEntity -> handleElementEntity(elementEntity,filteredItem));
}
- private void handleElementEntity(ElementEntity elementEntity, String filteredItem) {
+ private void handleElementEntity(ElementEntity elementEntity, Set<String> filteredItem) {
try {
String itemId = elementEntity.getItemId();
- if (filteredItem != null && !itemId.contains(filteredItem)){
+
+ if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)){
return;
}
String versionId = elementEntity.getVersionId();
@@ -42,11 +44,18 @@ public class ElementHandler {
if (!isNull(namespace)){
namespacePath = namespace.replace(ELEMENT_NAMESPACE_SPLITTER,separator)+separator;
}
- Path elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
- + separator + versionId + separator + space + separator + namespacePath+ separator + elementId);
+ Path elementDirectoryPath;
+ if (!isNull(namespace)){
+ elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
+ + separator + versionId + separator + space + separator + namespacePath+ separator + elementId);
+ } else {
+ elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
+ + separator + versionId + separator + space + separator + elementId);
+ }
+
if (notExists(elementDirectoryPath)) {
- createDirectories(elementDirectoryPath);
- }
+ Path created = createDirectories(elementDirectoryPath);
+ }
String info = elementEntity.getInfo();
if (!isNull(info)) {
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
index 9eea182609..710b731f8b 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
@@ -1,9 +1,11 @@
package org.openecomp.core.tools.Commands.exportdata;
+import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Item;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDao;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDaoFactory;
+import com.google.common.base.Strings;
import org.openecomp.core.tools.Commands.ExportDataCommand;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.sdc.logging.api.Logger;
@@ -13,11 +15,14 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.Set;
-import static java.nio.file.Files.*;
import static java.io.File.separator;
-import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
+import static java.nio.file.Files.*;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX;
public class ItemHandler {
private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
@@ -27,21 +32,42 @@ public class ItemHandler {
ImportProperties.initParams();
}
- public void createItemsData(SessionContext context, String filteredItem) throws URISyntaxException, IOException {
+ public void createItemsData(SessionContext context, Set<String> filteredItem) throws URISyntaxException, IOException {
+ final List<Item> items = new ArrayList<>();
+ if (filteredItem.isEmpty()) {
+ items.addAll(getItemDao(context).list(context));
+ } else {
+ Optional<Item> item = addItem(context, filteredItem.iterator().next(), items);
+ item.ifPresent(foundedItem -> {
+ Object vendorId = foundedItem.getInfo().getProperty("vendorId");
+ if (vendorId != null) {
+ String vendorIdStr = vendorId.toString();
+ addItem(context, vendorIdStr, items);
+ filteredItem.add(vendorIdStr);
+ }
+ });
+ }
+
+ items.parallelStream().forEach(item -> createItemDirectoryAndFiles(item, filteredItem));
+
+ }
+
- List<Item> items = getItemDao(context).list(context);
- items.parallelStream().forEach(item -> createItemDirectoryAndFiles(item,filteredItem));
+ private Optional<Item> addItem(SessionContext context, String filteredItem, List<Item> items) {
+ Optional<Item> item = getItemDao(context).get(context, new Id(filteredItem));
+ item.ifPresent(itemData -> items.add(itemData));
+ return item;
}
- private final void createItemDirectoryAndFiles(Item item,String filteredItem) {
+ private final void createItemDirectoryAndFiles(Item item, Set<String> filteredItem) {
try {
String itemId = item.getId().getValue();
- if (filteredItem != null && !itemId.contains(filteredItem)){
+ if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)) {
return;
}
- Path itemPath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator + itemId);
- Path itemFilePath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator +
+ Path itemPath = Paths.get(ImportProperties.ROOT_DIRECTORY + separator + itemId);
+ Path itemFilePath = Paths.get(ImportProperties.ROOT_DIRECTORY + separator +
itemId + separator + itemId + JSON_POSTFIX);
if (notExists(itemPath)) {
createDirectories(itemPath);
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
index b8d82958c9..e8e703bff0 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
@@ -17,6 +17,7 @@ import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.ROOT
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Set;
public class VersionHandler {
private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
@@ -24,17 +25,17 @@ public class VersionHandler {
public VersionHandler() {
}
- public void loadVersions(String filteredItem) {
+ public void loadVersions(Set<String> filteredItem) {
VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
versionCassandraLoader.list().forEach(versionEntity -> handleVersionEntity(versionEntity,filteredItem));
VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader();
versionInfoCassandraLoader.list().forEach(versionInfoEntity -> handleVersionInfo(versionInfoEntity,filteredItem));
}
- private void handleVersionEntity(VersionEntity versionEntity, String filteredItem) {
+ private void handleVersionEntity(VersionEntity versionEntity, Set<String> filteredItem) {
try {
String itemId = versionEntity.getItemId();
- if (filteredItem != null && !itemId.contains(filteredItem)){
+ if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)){
return;
}
String versionId = versionEntity.getVersionId();
@@ -55,7 +56,7 @@ public class VersionHandler {
}
- private void handleVersionInfo(VersionInfoEntity versionInfoEntity, String filteredItem) {
+ private void handleVersionInfo(VersionInfoEntity versionInfoEntity, Set<String> filteredItem) {
try {
String itemId = versionInfoEntity.getEntityId();
Path itemDirectory = Paths.get( ROOT_DIRECTORY + separator + itemId);
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
index 7ba830906c..d51458aff1 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
@@ -1,5 +1,6 @@
package org.openecomp.core.tools.Commands.importdata;
+import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import org.openecomp.core.tools.store.ElementCassandraLoader;
import org.openecomp.core.tools.store.ElementNamespaceHandler;
@@ -15,21 +16,26 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import static java.io.File.separator;
import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
public class ElementImport {
private static final Logger logger = LoggerFactory.getLogger(ElementImport.class);
+ public static final String ROOT_ITEM = Id.ZERO.getValue();
+
private ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader();
private ElementNamespaceHandler cassandraElementRepository = new ElementNamespaceHandler();
private VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
- public void loadPath(SessionContext sessionContext, Path elementDir, String elementId, String[] pathObjects) {
+ public void loadPath(SessionContext sessionContext, Path elementDir, String elementId, String[]
+ pathObjects) {
try {
+ if (!Files.isDirectory(elementDir)){
+ return;
+ }
// load info file
ElementEntity elementEntity = new ElementEntity();
Path infoFilePath = Paths.get(elementDir.toString() + separator + ELEMENT_INFO_PREFIX
@@ -38,7 +44,6 @@ public class ElementImport {
String info = new String(Files.readAllBytes(infoFilePath));
elementEntity.setInfo(info);
}
-
// load relation file
Path realtionsFilePath = Paths.get(elementDir.toString() + separator
+ ELEMENT_RELATION_PREFIX + elementId + JSON_POSTFIX);
@@ -58,7 +63,7 @@ public class ElementImport {
//load visualization
Path visualFilePath = Paths.get(elementDir.toString() + separator
- + ELEMENT_VISUALIZATION_PREFIX + elementId );
+ + ELEMENT_VISUALIZATION_PREFIX + elementId);
if (Files.exists(visualFilePath)) {
byte[] bytes = Files.readAllBytes(visualFilePath);
ByteBuffer visualization = ByteBuffer.wrap(bytes);
@@ -67,45 +72,60 @@ public class ElementImport {
//load searchable
Path searchableFilePath = Paths.get(elementDir.toString() + separator
- + ELEMENT_SEARCHABLE_PREFIX + elementId );
+ + ELEMENT_SEARCHABLE_PREFIX + elementId);
if (Files.exists(searchableFilePath)) {
byte[] bytes = Files.readAllBytes(searchableFilePath);
ByteBuffer searchable = ByteBuffer.wrap(bytes);
elementEntity.setSearchableData(searchable);
}
-
+ String element_Id = pathObjects[pathObjects.length - 1];
elementEntity.setSpace(pathObjects[2]);
elementEntity.setItemId(pathObjects[0]);
elementEntity.setVersionId(pathObjects[1]);
- elementEntity.setElement_id(pathObjects[pathObjects.length - 1]);
+ elementEntity.setElement_id(element_Id);
elementEntity.setNamespace(getNameSpace(pathObjects));
elementEntity.setParentId(getParentId(pathObjects));
- elementEntity.setSubElementIds(getAllSubElementsIds(elementDir));
+ elementEntity.setSubElementIds(getAllSubElementsIds(elementDir, element_Id));
elementCassandraLoader.createEntity(elementEntity);
cassandraElementRepository.createElementNamespace(elementEntity);
versionCassandraLoader.insertElementToVersion(elementEntity);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
}
}
private String getParentId(String[] pathObjects) {
- if (pathObjects.length <= 4) {
+
+ if (pathObjects[pathObjects.length - 1].equals(ROOT_ITEM)) {
return null;
}
+ if (pathObjects.length == 4) {
+ return ROOT_ITEM;
+ }
return pathObjects[pathObjects.length - 2];
}
- private Set<String> getAllSubElementsIds(Path root) throws IOException {
- try (Stream<Path> walk = Files.walk(root)) {
- return walk.filter(path -> Files.isDirectory(path))
- .map(path -> path.toFile().getName() ).collect(Collectors.toSet());
+ private Set<String> getAllSubElementsIds(Path root, String elementId) throws IOException {
+ if (elementId.equals(ROOT_ITEM)) {
+ root = root.getParent();
+ }
+ File file = root.toFile();
+ Set<String> retVal = new HashSet<>();
+ File[] files = file.listFiles();
+ for (File f : files){
+ if (f.isDirectory()){
+ retVal.add(f.getName());
+ }
}
+ retVal.remove(ROOT_ITEM);
+ return retVal;
+
}
private String getNameSpace(String[] pathObjects) {
if (pathObjects.length <= 4) {
- return null;
+ return "";
}
if (pathObjects.length == 5) {
return pathObjects[3];
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
index c7042743c2..9ec5d639c2 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
@@ -31,8 +31,11 @@ public class ItemImport {
Item item = JsonUtil.json2Object(itemJson, Item.class);
ItemDao itemDao = getItemDao(sessionContext);
itemDao.create(sessionContext, item.getId(), item.getInfo(), item.getCreationTime());
+ logger.info("Item Created :"+item.getInfo().getName()+" , "+item.getId());
+ System.out.println("Item Created :"+item.getInfo().getName()+" , "+item.getId());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
}
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
index 020b2f3c47..15f8b02e2b 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
@@ -4,10 +4,14 @@ import com.amdocs.zusammen.datatypes.SessionContext;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import javax.validation.constraints.Min;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.stream.Stream;
public class TreeWalker {
@@ -21,7 +25,10 @@ public class TreeWalker {
}
private static final void handlePath(SessionContext sessionContext, Path path, Path root,String filterItem) {
- String logicalPath = path.toString().replace(root.toString()+File.separator, "");
+ String logicalPath = path.toString().replace(root.toString(), "");
+ if (logicalPath.startsWith(File.separator)){
+ logicalPath = logicalPath.substring(1);
+ }
String[] splitted = logicalPath.split(File.separator);
if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
return;
@@ -42,7 +49,7 @@ public class TreeWalker {
break;
default:
//handle elements
- new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);
+ new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);
break;
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java
index 6447f85ea7..2f6693d133 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java
@@ -10,12 +10,14 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Scanner;
+import java.util.Set;
+import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class ZipUtils {
- public static void createZip(String zipFileName, Path dir, String filterItem) throws Exception {
+ public static void createZip(String zipFileName, Path dir, Set<String> filterItem) throws Exception {
File dirObj = dir.toFile();
try (
FileOutputStream fileOutputStream = new FileOutputStream(zipFileName);
@@ -24,29 +26,34 @@ public class ZipUtils {
}
}
- public static final String cleanStr(String inFilterStr) {
- if (Objects.isNull(inFilterStr)) {
- return inFilterStr;
- }
- Scanner scan = new Scanner(inFilterStr);
- while (scan.hasNextLine()) {
- inFilterStr = scan.nextLine().replaceAll("[^a-zA-Z0-9]", "");
- }
- return inFilterStr;
+ public static final Set<String> cleanStr(Set<String> inFilterStrs) {
+ return inFilterStrs.stream().map(inFilterStr -> {
+ if (Objects.isNull(inFilterStr)) {
+ return inFilterStr;
+ }
+ Scanner scan = new Scanner(inFilterStr);
+ while (scan.hasNextLine()) {
+ inFilterStr = scan.nextLine().replaceAll("[^a-zA-Z0-9]", "");
+ }
+ return inFilterStr;
+ }
+ ).collect(Collectors.toSet());
}
- static void addDir(File dirObj, ZipOutputStream out, String root, String filterItem) throws IOException {
+ static void addDir(File dirObj, ZipOutputStream out, String root, Set<String> filterItem) throws IOException {
File[] files = dirObj.listFiles();
filterItem = cleanStr(filterItem);
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
addDir(files[i], out, root, filterItem);
+ String filePath = files[i].getAbsolutePath().replace(root + File.separator, "") + "/";
+ out.putNextEntry(new ZipEntry(filePath));
continue;
}
try (FileInputStream in = new FileInputStream((files[i].getAbsolutePath()))) {
String filePath = files[i].getAbsolutePath().replace(root + File.separator, "");
- if (filterItem == null || filePath.contains(filterItem)) {
+ if (filterItem.isEmpty() || filterItem.stream().anyMatch(s -> filePath.contains(s))) {
out.putNextEntry(new ZipEntry(filePath));
try {
ByteStreams.copy(in, out);
@@ -74,9 +81,16 @@ public class ZipUtils {
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(outputFolder.toString() + File.separator + fileName);
- new File(newFile.getParent()).mkdirs();
- try (FileOutputStream fos = new FileOutputStream(newFile)) {
- ByteStreams.copy(zis, fos);
+ if (ze.isDirectory()) {
+ Path path = newFile.toPath();
+ if (!Files.exists(path)) {
+ Files.createDirectories(path);
+ }
+ } else {
+ new File(newFile.getParent()).mkdirs();
+ try (FileOutputStream fos = new FileOutputStream(newFile)) {
+ ByteStreams.copy(zis, fos);
+ }
}
ze = zis.getNextEntry();
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml b/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
index b1c1335302..a13dc82e22 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
@@ -1,282 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration scan="true" scanPeriod="5 seconds">
+<configuration>
- <property scope="system" name="ECOMP-component-name" value="ASDC" />
- <property scope="system" name="ECOMP-subcomponent-name" value="ASDC-BE" />
- <property file="${config.home}/catalog-be/configuration.yaml" />
- <property scope="context" name="enable-all-log" value="false" />
-
- <!--statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
- <include resource="asdc_debug_logback.xml"/-->
-
- <!-- value used by pattern field list (| - is inter-field separator, || - unavailable or not applicable field value) (m - mandatory, o- optional)-->
- <!--timestamp(m)| requestID(m)| serviceInstanceID(o)| threadID(m)| physicalServerName(o)| serviceName(m)| userID(m)| logLevel(m)| severity(o)| serverIpAddress(m)| serverName(m)| clientIpAddress(o)| className(m)| timer(o)| detailedMessage(o)-->
- <property name="default-log-pattern"
- value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{uuid}|%X{serviceInstanceID}|%thread||${ECOMP-subcomponent-name}|%X{userId}|%level|%X{alarmSeverity}|%X{localAddr}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
-
- <property name="asdc-debug-log-pattern" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestId}|%msg %n"/>
-
- <!-- All log -->
- <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
- <then>
- <appender name="ALL_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log
- </file>
-
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <appender name="ASYNC_ALL" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="ALL_ROLLING" />
- </appender>
- </then>
- </if>
-
- <!-- Error log -->
- <appender name="ERROR_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/Error.log
- </file>
-
- <!-- Audit messages filter - deny audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>AUDIT_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- Transaction messages filter - deny Transaction messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- deny all events with a level below INFO, that is TRACE and DEBUG -->
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>INFO</level>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/Error.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
- <pattern>${default-log-pattern}</pattern>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
- <!-- Debug log -->
- <appender name="DEBUG_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log
- </file>
-
- <!-- No need to deny audit messages - they are INFO only, will be denied
- anyway -->
- <!-- Transaction messages filter - deny Transaction messages, there are
- some DEBUG level messages among them -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
- <!-- accept DEBUG and TRACE level -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
- <expression>
- e.level.toInt() &lt;= DEBUG.toInt()
- </expression>
- </evaluator>
- <OnMismatch>DENY</OnMismatch>
- <OnMatch>NEUTRAL</OnMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Debug log -->
- <appender name="MIGRATION_DEBUG_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/cassandra2zusammen_migration_debug.log
- </file>
-
- <!-- No need to deny audit messages - they are INFO only, will be denied
- anyway -->
- <!-- Transaction messages filter - deny Transaction messages, there are
- some DEBUG level messages among them -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- accept DEBUG and TRACE level -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
- <expression>
- e.level.toInt() &lt;= DEBUG.toInt()
- </expression>
- </evaluator>
- <OnMismatch>DENY</OnMismatch>
- <OnMatch>NEUTRAL</OnMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug_by_package.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${asdc-debug-log-pattern}</pattern>
- </encoder>
- </appender>
- <!-- Audit log -->
- <appender name="AUDIT_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
-
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log
- </file>
-
- <!-- Audit messages filter - accept audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>AUDIT_MARKER</marker>
- </evaluator>
- <onMismatch>DENY</onMismatch>
- <onMatch>ACCEPT</onMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- SdncTransaction log -->
- <appender name="TRANSACTION_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
-
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log
- </file>
-
- <!-- Transaction messages filter - accept audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>DENY</onMismatch>
- <onMatch>ACCEPT</onMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Asynchronicity Configurations -->
- <appender name="ASYNC_DEBUG" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="DEBUG_ROLLING" />
- </appender>
-
- <appender name="ASYNC_TRANSACTION" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="TRANSACTION_ROLLING" />
- </appender>
-
- <appender name="ASYNC_ERROR" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="ERROR_ROLLING" />
- </appender>
-
-
- <root level="INFO">
- <appender-ref ref="ASYNC_ERROR" />
- <appender-ref ref="ASYNC_DEBUG" />
- <appender-ref ref="AUDIT_ROLLING" />
- <appender-ref ref="ASYNC_TRANSACTION" />
- <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
- <then>
- <appender-ref ref="ALL_ROLLING" />
- </then>
- </if>
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
</root>
- <logger name="org.openecomp.sdc" level="INFO" />
-
- <logger name="org.openecomp.core" level="DEBUG" additivity="false">
- <appender-ref ref="MIGRATION_DEBUG_ROLLING" />
- </logger>
-</configuration>
-
-
+</configuration> \ No newline at end of file