diff options
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java')
8 files changed, 309 insertions, 0 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java new file mode 100644 index 0000000000..185e80030f --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java @@ -0,0 +1,81 @@ +package org.openecomp.core.tools.Commands; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.ItemCassandraDao; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.VersionCassandraDao; +import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader; +import org.openecomp.core.tools.loaders.zusammen.VspGeneralLoader; +import org.openecomp.core.tools.store.ElementHandler; +import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; +import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository; +import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ResetOldVersion { + + + public static Map<String, List<String>> itemVersionMap = new HashMap<>(); + + public static void reset(SessionContext context, String oldVersion) { + + + + CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); + + loadItemVersionInfo(context); + + Map<String, ElementEntity> generalElementMap = + VspGeneralLoader.load(context, + itemVersionMap); + + generalElementMap.values().forEach(elementEntity -> updateOldVersionFlag(elementEntity,oldVersion)); + + + itemVersionMap.entrySet().forEach(entry->entry.getValue().stream().filter + (version->generalElementMap.containsKey(context.getUser().getUserName()+"_"+entry.getKey() + +"_"+version)).forEach(version->ElementHandler.update(context, + entry.getKey(),version,generalElementMap.get(context.getUser().getUserName()+"_"+entry.getKey() + +"_"+version)))); + } + + private static void updateOldVersionFlag(ElementEntity elementEntity, String oldVersion) { + elementEntity.getInfo().addProperty("oldVersion",oldVersion); + } + + + private static void loadItemVersionInfo(SessionContext context) { + + List<String> items = new ArrayList<>(); + System.setProperty("cassandra.dox.keystore", "dox"); + VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader(); + Collection<VersionInfoEntity> versions = + versionInfoCassandraLoader.list(); + + versions.stream().filter(versionInfoEntity -> versionInfoEntity.getEntityType().equals + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE)).forEach + (versionInfoEntity + -> items.add(versionInfoEntity.getEntityId())); + System.setProperty("cassandra.dox.keystore", "zusammen_dox"); + VersionCassandraDao versionCassandraDao = new VersionCassandraDao(); + + items + .forEach(itemId -> versionCassandraDao.list(context, context.getUser().getUserName(), new Id + (itemId)).forEach(itemVersion -> addItemVersion(itemId, itemVersion.getId()))); + + } + + private static void addItemVersion(String itemId, Id versionId) { + if (!itemVersionMap.containsKey(itemId)) { + itemVersionMap.put(itemId, new ArrayList<>()); + } + itemVersionMap.get(itemId).add(versionId.getValue()); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java new file mode 100644 index 0000000000..8840975a56 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.tools.loaders; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import java.util.Collection; + +public class VersionInfoCassandraLoader { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper<VersionInfoEntity> mapper = + noSqlDb.getMappingManager().mapper(VersionInfoEntity.class); + private static VersionInfoAccessor accessor = + noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); + + + + + public Collection<VersionInfoEntity> list() { + return accessor.getAll().all(); + } + + @Accessor + interface VersionInfoAccessor { + @Query("select * from version_info ") + Result<VersionInfoEntity> getAll(); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java new file mode 100644 index 0000000000..d92866bb47 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java @@ -0,0 +1,40 @@ +package org.openecomp.core.tools.loaders.zusammen; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext; +import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository; +import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class VspGeneralLoader { + public static Map<String, ElementEntity> load(SessionContext context, + Map<String, List<String>> vspItemVersionsMap) { + Map<String, ElementEntity> elementEntityMap = new HashMap<>(); + System.setProperty("cassandra.dox.keystore", "zusammen_dox"); + CassandraElementRepository cassandraElementRepository = new CassandraElementRepository(); + for (Map.Entry<String, List<String>> entry : vspItemVersionsMap.entrySet()) { + + for (String version : entry.getValue()) { + + Optional<ElementEntity> result = + cassandraElementRepository.get(context, new ElementEntityContext( + context.getUser().getUserName(), + new Id(entry.getKey()), + new Id(version)), + new ElementEntity(new Id(StructureElement.General.name()))); + if (result.isPresent()) { + elementEntityMap.put(context.getUser().getUserName() + "_" + entry.getKey() + + "_" + version, result.get()); + } + } + } + + return elementEntityMap; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java new file mode 100644 index 0000000000..78b915c525 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java @@ -0,0 +1,4 @@ +package org.openecomp.core.tools.loaders.zusammen; + +public class VspItemLoader { +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java new file mode 100644 index 0000000000..7bc4bb23fb --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java @@ -0,0 +1,76 @@ +package org.openecomp.core.tools.main; + +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import org.openecomp.core.tools.Commands.ResetOldVersion; +import org.openecomp.core.tools.util.ToolsUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.time.Duration; +import java.time.Instant; + +import static org.openecomp.core.tools.util.Utils.printMessage; + +public class ZusammenMainTool { + + private static final String GLOBAL_USER = "GLOBAL_USER"; + private static Logger logger = LoggerFactory.getLogger(ZusammenMainTool.class); + private static int status = 0; + + public static void main(String[] args) { + + String command = ToolsUtil.getParam("c",args); + if(command == null){ + printMessage(logger, + "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " + + "[additional arguments depending on the command] "); + System.exit(-1); + } + Instant startTime = Instant.now(); + + SessionContext context = new SessionContext(); + context.setUser(new UserInfo(GLOBAL_USER)); + context.setTenant("dox"); + + + switch (COMMANDS.valueOf(command)){ + case RESET_OLD_VERSION: + ResetOldVersion.reset(context,ToolsUtil.getParam("v",args)); + break; + case EXPORT: + break; + case IMPORT: + break; + + } + + Instant stopTime = Instant.now(); + Duration duration = Duration.between(startTime, stopTime); + long minutesPart = duration.toMinutes(); + long secondsPart = duration.minusMinutes(minutesPart).getSeconds(); + + + printMessage(logger, + "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" + + secondsPart + + " minutes"); + System.exit(status); + + } + + private enum COMMANDS{ + + + RESET_OLD_VERSION("reset-old-version"), + EXPORT("export"), + IMPORT("import"); + + COMMANDS(String command) { + this.command = command; + } + + private String command; + } + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java new file mode 100644 index 0000000000..2690130974 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java @@ -0,0 +1,26 @@ +package org.openecomp.core.tools.store; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext; +import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository; +import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; + +public class ElementHandler { + + private static final String GLOBAL_USER = "GLOBAL_USER"; + + public static void update(SessionContext context, + + String itemId, String versionId, + ElementEntity elementEntity) { + + ElementEntityContext elementContext; + elementContext = new ElementEntityContext(GLOBAL_USER, new Id(itemId), + new Id(versionId)); + CassandraElementRepository cassandraElementRepository = new CassandraElementRepository(); + cassandraElementRepository.update(context, elementContext, elementEntity); + + } +} + diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java new file mode 100644 index 0000000000..e2c80f0226 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java @@ -0,0 +1,14 @@ +package org.openecomp.core.tools.util; + +public class ToolsUtil { + + public static String getParam(String key, String[] args) { + + for (int j = 0; j < args.length; j++) { + if (args[j].equals("-" + key)) { + return args[j + 1]; + } + } + return null; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java new file mode 100644 index 0000000000..d1621ad672 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java @@ -0,0 +1,15 @@ +package org.openecomp.core.tools.util; + +import org.openecomp.sdc.logging.api.Logger; + +/** + * @author Avrahamg + * @since April 24, 2017 + */ +public class Utils { + public static void printMessage(Logger logger, String message) { + System.out.println(message); + logger.debug(message); + } +} + |