diff options
Diffstat (limited to 'openecomp-be')
15 files changed, 188 insertions, 14 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java index e2d987233e..496db14e53 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java @@ -165,9 +165,11 @@ public class VersionsImpl implements Versions { case Revert: revert(request.getRevisionRequest(), itemId, versionId); break; - case Reset: - throw new UnsupportedOperationException("Action reset not supported."); + case Clean: + versioningManager.clean(itemId, version); + break; default: + throw new UnsupportedOperationException(String.format("Action %s not supported.", request.getAction())); } return Response.ok().build(); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/VersionAction.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/VersionAction.java index c9d6f4e293..1dba03cedc 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/VersionAction.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/VersionAction.java @@ -24,5 +24,6 @@ public enum VersionAction { Sync, Commit, Revert, - Reset + Reset, + Clean } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java index 23eddadbf7..ca37b2200a 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java @@ -62,6 +62,8 @@ public interface ZusammenAdaptor { void forceSyncVersion(SessionContext context, Id itemId, Id versionId); + void cleanVersion(SessionContext context, Id itemId, Id versionId); + Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, Id elementId); diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java index 1589c1a25b..fd44073bb9 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java @@ -65,6 +65,8 @@ public interface ZusammenConnector { void forceSyncVersion(SessionContext context, Id itemId, Id versionId); + void cleanVersion(SessionContext context, Id itemId, Id versionId); + ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId); diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java index 83bbc5b49a..f8b048ce92 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java @@ -290,6 +290,17 @@ public class ZusammenConnectorImpl implements ZusammenConnector { } @Override + public void cleanVersion(SessionContext context, Id itemId, Id versionId) { + Response<Void> response = + versionAdaptorFactory.createInterface(context).delete(context, itemId, versionId); + if (!response.isSuccessful()) { + throw new SdcRuntimeException(String.format( + "failed to clean item Version. ItemId: %s, versionId: %s, message: %s", + itemId.getValue(), versionId.getValue(), response.getReturnCode().toString())); + } + } + + @Override public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) { Response<ItemVersionConflict> response = versionAdaptorFactory.createInterface(context).getConflict(context, itemId, versionId); diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java index 968ff28963..1c63ff8e2e 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java @@ -277,6 +277,11 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor { } @Override + public void cleanVersion(SessionContext context, Id itemId, Id versionId) { + connector.cleanVersion(context, itemId, versionId); + } + + @Override public void revert(SessionContext context, Id itemId, Id versionId, Id revisionId) { connector.revertVersionRevision(context, itemId, versionId, revisionId); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java index dbf5ad9bf9..21d447e8de 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java @@ -367,6 +367,11 @@ public class ServiceModelDaoFactoryTest { } @Override + public void cleanVersion(SessionContext sessionContext, Id itemId, Id versionId) { + + } + + @Override public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, Id elementId) { diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java index cbb234e3e2..06382b2ef6 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java @@ -43,4 +43,6 @@ public interface VersioningManager { List<Revision> listRevisions(String itemId, Version version); void updateVersion(String itemId, Version version); + + void clean(String itemId, Version version); } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionDao.java index f557e4d4ec..978ab435e0 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionDao.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionDao.java @@ -1,10 +1,9 @@ package org.openecomp.sdc.versioning.dao; -import org.openecomp.sdc.versioning.dao.types.Revision; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.util.List; import java.util.Optional; +import org.openecomp.sdc.versioning.dao.types.Revision; +import org.openecomp.sdc.versioning.dao.types.Version; public interface VersionDao { List<Version> list(String itemId); @@ -23,6 +22,8 @@ public interface VersionDao { void forceSync(String itemId, Version version); + void clean(String itemId, Version version); + void revert(String itemId, Version version, String revisionId); List<Revision> listRevisions(String itemId, Version version); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java index 32c17dbfce..3b783d5d25 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java @@ -1,5 +1,7 @@ package org.openecomp.sdc.versioning.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Info; @@ -8,6 +10,10 @@ import com.amdocs.zusammen.datatypes.item.ItemVersionData; import com.amdocs.zusammen.datatypes.item.ItemVersionStatus; import com.amdocs.zusammen.datatypes.item.SynchronizationStatus; import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -19,13 +25,6 @@ import org.openecomp.sdc.versioning.dao.types.SynchronizationState; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionState; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - public class VersionZusammenDaoImpl implements VersionDao { public static final class ZusammenProperty { @@ -111,6 +110,11 @@ public class VersionZusammenDaoImpl implements VersionDao { } @Override + public void clean(String itemId, Version version) { + zusammenAdaptor.cleanVersion(createSessionContext(), new Id(itemId), new Id(version.getId())); + } + + @Override public void revert(String itemId, Version version, String revisionId) { zusammenAdaptor.revert(createSessionContext(), new Id(itemId), new Id(version.getId()), new Id(revisionId)); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java index 091def645d..21b738746d 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java @@ -183,4 +183,9 @@ public class VersioningManagerImpl implements VersioningManager { versionDao.update(itemId, version); } + @Override + public void clean(String itemId, Version version) { + versionDao.clean(itemId, version); + } + } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java new file mode 100644 index 0000000000..96bc22e204 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java @@ -0,0 +1,69 @@ +package org.openecomp.core.tools.commands; + +import static org.openecomp.core.tools.commands.CommandName.CLEAN_USER_DATA; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import java.util.Collection; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.openecomp.core.zusammen.db.ZusammenConnector; +import org.openecomp.core.zusammen.db.ZusammenConnectorFactory; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +public class CleanUserDataCommand extends Command { + + private static final Logger LOGGER = LoggerFactory.getLogger(CleanUserDataCommand.class); + private static final String ITEM_ID_OPTION = "i"; + private static final String USER_OPTION = "u"; + + CleanUserDataCommand() { + options.addOption( + Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id").desc("id of the item to clean, mandatory") + .build()); + options.addOption(Option.builder(USER_OPTION).hasArg().argName("user") + .desc("the user of which the item data will be cleaned for, mandatory").build()); + } + + @Override + public boolean execute(String[] args) { + CommandLine cmd = parseArgs(args); + if (!cmd.hasOption(ITEM_ID_OPTION) || !cmd.hasOption(USER_OPTION)) { + LOGGER.error("Arguments i and u are mandatory"); + return false; + } + String itemId = cmd.getOptionValue(ITEM_ID_OPTION); + String user = cmd.getOptionValue(USER_OPTION); + + SessionContext context = createSessionContext(user); + ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface(); + + Id itemIdObj = new Id(itemId); + Collection<ItemVersion> versions = zusammenConnector.listPublicVersions(context, itemIdObj); + for (ItemVersion version : versions) { + try { + zusammenConnector.cleanVersion(context, itemIdObj, version.getId()); + } catch (Exception e) { + LOGGER.error( + String.format("Error occurred while cleaning item %s version %s from user %s space", itemId, + version.getId(), user), e); + } + } + return true; + } + + @Override + public CommandName getCommandName() { + return CLEAN_USER_DATA; + } + + private static SessionContext createSessionContext(String user) { + SessionContext sessionContext = new SessionContext(); + sessionContext.setUser(new UserInfo(user)); + sessionContext.setTenant("dox"); + return sessionContext; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java index 7fa04a3907..7490f03a82 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java @@ -6,5 +6,7 @@ public enum CommandName { IMPORT, HEAL_ALL, POPULATE_USER_PERMISSIONS, - ADD_CONTRIBUTOR + ADD_CONTRIBUTOR, + CLEAN_USER_DATA, + DELETE_PUBLIC_VERSION } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java index b6cc0487ea..dc237b5ccc 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java @@ -35,6 +35,8 @@ public class CommandsHolder { new HealAll().register(); new PopulateUserPermissions().register(); new AddContributorCommand().register(); + new CleanUserDataCommand().register(); + new DeletePublicVersionCommand().register(); } private CommandsHolder() { diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java new file mode 100644 index 0000000000..fee07501d4 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java @@ -0,0 +1,61 @@ +package org.openecomp.core.tools.commands; + +import static org.openecomp.core.tools.commands.CommandName.DELETE_PUBLIC_VERSION; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.openecomp.core.zusammen.db.ZusammenConnector; +import org.openecomp.core.zusammen.db.ZusammenConnectorFactory; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +public class DeletePublicVersionCommand extends Command { + + private static final Logger LOGGER = LoggerFactory.getLogger(DeletePublicVersionCommand.class); + private static final String ITEM_ID_OPTION = "i"; + private static final String VERSION_ID_OPTION = "v"; + + DeletePublicVersionCommand() { + options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id") + .desc("id of the item to delete from public, mandatory").build()); + options.addOption(Option.builder(VERSION_ID_OPTION).hasArg().argName("version_id") + .desc("id of the version to delete from public, mandatory").build()); + } + + @Override + public boolean execute(String[] args) { + CommandLine cmd = parseArgs(args); + if (!cmd.hasOption(ITEM_ID_OPTION) || !cmd.hasOption(VERSION_ID_OPTION)) { + LOGGER.error("Arguments i and v are mandatory"); + return false; + } + String itemId = cmd.getOptionValue(ITEM_ID_OPTION); + String versionId = cmd.getOptionValue(VERSION_ID_OPTION); + + SessionContext context = createSessionContext(); + ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface(); + + try { + zusammenConnector.cleanVersion(context, new Id(itemId), new Id(versionId)); + } catch (Exception e) { + LOGGER.error(String.format("Error occurred while deleting item %s version %s from public space", itemId, + versionId), e); + } + return true; + } + + @Override + public CommandName getCommandName() { + return DELETE_PUBLIC_VERSION; + } + + private static SessionContext createSessionContext() { + SessionContext sessionContext = new SessionContext(); + sessionContext.setUser(new UserInfo("public")); + sessionContext.setTenant("dox"); + return sessionContext; + } +} |