diff options
13 files changed, 53 insertions, 585 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java index 0641524038..99e0da0116 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java @@ -20,68 +20,54 @@ package org.openecomp.sdc.common.transaction.mngr; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - import org.openecomp.sdc.common.transaction.api.RollbackHandler; import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum; import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum; import org.openecomp.sdc.common.util.MethodActivationStatusEnum; +import fj.P; import fj.data.Either; +import fj.data.HashMap; +import fj.data.List; public class RollbackManager { - private Map<DBTypeEnum, RollbackHandler> rollBackHandlersMap; - private Integer transactionId; - private String userId, actionType; + private final HashMap<DBTypeEnum, RollbackHandler> rollbackHandlersMap; + private final Integer transactionId; + private final String userId; + private final String actionType; - RollbackManager(Integer transactionId, String userId, String actionType, List<RollbackHandler> roleBackHandlers) { + RollbackManager(Integer transactionId, String userId, String actionType, Iterable<RollbackHandler> rollbackHandlers) { this.transactionId = transactionId; this.userId = userId; this.actionType = actionType; - rollBackHandlersMap = new HashMap<>(); - for (RollbackHandler handler : roleBackHandlers) { - rollBackHandlersMap.put(handler.getDBType(), handler); - } - + this.rollbackHandlersMap = HashMap.from(List.iterableList(rollbackHandlers).map(i -> P.p(i.getDBType(), i))); } public DBActionCodeEnum transactionRollback() { - DBActionCodeEnum rollbackResult = DBActionCodeEnum.SUCCESS; - Iterator<RollbackHandler> handlersItr = rollBackHandlersMap.values().iterator(); - while (handlersItr.hasNext()) { - RollbackHandler handler = handlersItr.next(); - DBActionCodeEnum rollbackCode = handler.doRollback(); - if (rollbackCode == DBActionCodeEnum.FAIL_GENERAL) { - rollbackResult = DBActionCodeEnum.FAIL_GENERAL; - } - } - - return rollbackResult; + List<DBActionCodeEnum> results = rollbackHandlersMap.values().map(RollbackHandler::doRollback); + boolean failure = results.exists(r -> r == DBActionCodeEnum.FAIL_GENERAL); + return failure ? DBActionCodeEnum.FAIL_GENERAL : DBActionCodeEnum.SUCCESS; } protected Either<RollbackHandler, MethodActivationStatusEnum> addRollbackHandler(RollbackHandler rollbackHandler) { Either<RollbackHandler, MethodActivationStatusEnum> result; - if (rollBackHandlersMap.containsKey(rollbackHandler.getDBType())) { + if (rollbackHandlersMap.contains(rollbackHandler.getDBType())) { result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED); } else { - rollBackHandlersMap.put(rollbackHandler.getDBType(), rollbackHandler); + rollbackHandlersMap.set(rollbackHandler.getDBType(), rollbackHandler); result = Either.left(rollbackHandler); } return result; } - protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(DBTypeEnum dbType) { + protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(final DBTypeEnum dbType) { - final DBTypeEnum dbTypeFinal = dbType; RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) { @Override public DBTypeEnum getDBType() { - return dbTypeFinal; + return dbType; } @Override @@ -89,19 +75,13 @@ public class RollbackManager { return true; } }; - Either<RollbackHandler, MethodActivationStatusEnum> result = addRollbackHandler(rollbackHandler); - - return result; + return addRollbackHandler(rollbackHandler); } protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) { - Either<RollbackHandler, MethodActivationStatusEnum> result; - if (rollBackHandlersMap.containsKey(dbType)) { - result = Either.left(rollBackHandlersMap.get(dbType)); - } else { - result = Either.right(MethodActivationStatusEnum.NOT_FOUND); - } - return result; + // need to swap here because the uses of Either in SDC appears to be opposite of convention + // by convention left is failure; in SDC right is failure + return rollbackHandlersMap.get(dbType).toEither(MethodActivationStatusEnum.NOT_FOUND).swap(); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java index c401586383..c05431ac7f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java @@ -20,14 +20,13 @@ package org.openecomp.sdc.common.transaction.mngr; -import java.util.List; +import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Resource; import org.openecomp.sdc.be.dao.impl.ESCatalogDAO; import org.openecomp.sdc.be.dao.titan.TitanGenericDao; -import org.openecomp.sdc.common.datastructure.CapList; import org.openecomp.sdc.common.transaction.api.ITransactionSdnc; import org.openecomp.sdc.common.transaction.api.TransactionUtils; import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum; @@ -35,6 +34,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import com.google.common.collect.EvictingQueue; +import com.google.common.collect.Queues; + @Component("transactionManager") public class TransactionManager { @@ -42,7 +44,7 @@ public class TransactionManager { private AtomicInteger transactionIDCounter = new AtomicInteger(0); - private List<ITransactionSdnc> transactions; + private Queue<ITransactionSdnc> transactions; @Resource private ESCatalogDAO esCatalogDao; @Resource @@ -91,7 +93,10 @@ public class TransactionManager { private synchronized void init() { if (transactions == null) { log.info("TransactionManager Initialized"); - transactions = new CapList<>(TransactionUtils.MAX_SIZE_TRANSACTION_LIST); + EvictingQueue<ITransactionSdnc> queue = EvictingQueue + .<ITransactionSdnc>create(TransactionUtils.MAX_SIZE_TRANSACTION_LIST); + // make thread-safe + transactions = Queues.synchronizedQueue(queue); } } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java index fb0b160b09..1ab27fc930 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java @@ -36,7 +36,6 @@ import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetResponse; import org.elasticsearch.client.Client; import org.openecomp.sdc.be.dao.es.ElasticSearchClient; -import org.openecomp.sdc.be.dao.utils.Exceptions; import org.openecomp.sdc.exception.IndexingServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,7 +94,7 @@ public abstract class ESGenericIdDAO implements IGenericIdDAO { try { ret = (T) jsonMapper.readValue(response.getSourceAsString(), clazz); } catch (IOException e) { - Exceptions.convertToRuntimeEx(e); + throw new RuntimeException(e); } return ret; } @@ -119,7 +118,7 @@ public abstract class ESGenericIdDAO implements IGenericIdDAO { val = jsonMapper.readValue(getItemResponse.getResponse().getSourceAsString(), clazz); result.add(val); } catch (IOException e) { - Exceptions.convertToRuntimeEx(e); + throw new RuntimeException(e); } } } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java index c24325aefb..77aac87427 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java @@ -31,7 +31,6 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.sort.SortBuilder; import org.openecomp.sdc.be.dao.es.ElasticSearchClient; -import org.openecomp.sdc.be.dao.utils.Exceptions; /** * Elastic search dao that manages search operations. @@ -83,7 +82,7 @@ public class ESGenericSearchDAO extends ESGenericIdDAO implements IGenericSearch try { result.add(getJsonMapper().readValue(searchResponse.getHits().getAt(i).getSourceAsString(), clazz)); } catch (IOException e) { - Exceptions.convertToRuntimeEx(e); + throw new RuntimeException(e); } } @@ -114,7 +113,7 @@ public class ESGenericSearchDAO extends ESGenericIdDAO implements IGenericSearch val = getJsonMapper().readValue(hit, clazz); result.add(val); } catch (IOException e) { - Exceptions.convertToRuntimeEx(e); + throw new RuntimeException(e); } } return result; diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/Exceptions.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/Exceptions.java deleted file mode 100644 index fd0a6754ab..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/Exceptions.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============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.sdc.be.dao.utils; - -public final class Exceptions { - private Exceptions() { - } - - public static RuntimeException convertToRuntimeEx(Throwable t) { - return Exceptions.<RuntimeException>convertToRTException(t); - } - - @SuppressWarnings("unchecked") - private static <T extends Throwable> T convertToRTException(Throwable t) throws T { - throw (T) t; - } -} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java index 0f36f09ca8..2847367999 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java @@ -21,11 +21,11 @@ package org.openecomp.sdc.be.model.operations.impl; import java.lang.reflect.Type; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -118,7 +118,6 @@ public abstract class AbstractOperation { log.debug("Before adding {} to graph. data = {}", defName, someData); - @SuppressWarnings("unchecked") Either<TitanVertex, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData); log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData); @@ -284,27 +283,15 @@ public abstract class AbstractOperation { PropertyTypeValidator validator = type.getValidator(); - boolean isValid = validator.isValid(value, innerType, dataTypes); - if (true == isValid) { - return true; - } else { - return false; - } - + return validator.isValid(value, innerType, dataTypes); } public boolean isEmptyValue(String value) { - if (value == null) { - return true; - } - return false; + return value == null; } public boolean isNullParam(String value) { - if (value == null) { - return true; - } - return false; + return value == null; } protected StorageOperationStatus validateAndUpdateComplexValue(IComplexDefaultValue propertyDefinition, String propertyType, @@ -339,11 +326,7 @@ public abstract class AbstractOperation { if (jsonElement == null || jsonElement.isJsonNull()) { value = EMPTY_VALUE; } else { - if (jsonElement.toString().isEmpty()) { - value = ""; - } else { - value = jsonElement.toString(); - } + value = jsonElement.toString(); } return value; @@ -376,18 +359,11 @@ public abstract class AbstractOperation { */ public List<String> convertConstraintsToString(List<PropertyConstraint> constraints) { - List<String> result = null; - - if (constraints != null && false == constraints.isEmpty()) { - result = new ArrayList<String>(); - for (PropertyConstraint propertyConstraint : constraints) { - String constraint = gson.toJson(propertyConstraint); - result.add(constraint); - } - + if (constraints == null || constraints.isEmpty()) { + return null; } - return result; + return constraints.stream().map(gson::toJson).collect(Collectors.toList()); } public List<PropertyConstraint> convertConstraints(List<String> constraints) { @@ -396,18 +372,13 @@ public abstract class AbstractOperation { return null; } - List<PropertyConstraint> list = new ArrayList<PropertyConstraint>(); Type constraintType = new TypeToken<PropertyConstraint>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create(); - for (String constraintJson : constraints) { - PropertyConstraint propertyConstraint = gson.fromJson(constraintJson, constraintType); - list.add(propertyConstraint); - } + return constraints.stream().map(c -> gson.fromJson(c, PropertyConstraint.class)).collect(Collectors.toList()); - return list; } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java index 2fcdf695be..f9057217a6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -155,8 +154,7 @@ public class GroupTypeOperation extends AbstractOperation implements IGroupTypeO @Override public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction) { - Function<String, Either<GroupTypeDefinition, TitanOperationStatus>> groupTypeGetter = uId -> getGroupTypeByUid(uId); - return getElementType(groupTypeGetter, uniqueId, inTransaction); + return getElementType(this::getGroupTypeByUid, uniqueId, inTransaction); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java index 796fc8dd34..adea89b9ea 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.model.operations.impl; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; import javax.annotation.Resource; @@ -167,8 +166,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp @Override public Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyType(String uniqueId, boolean inTransaction) { - Function<String, Either<PolicyTypeDefinition, TitanOperationStatus>> policyTypeGetter = uId -> getPolicyTypeByUid(uId); - return getElementType(policyTypeGetter, uniqueId, inTransaction); + return getElementType(this::getPolicyTypeByUid, uniqueId, inTransaction); } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/CapList.java b/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/CapList.java deleted file mode 100644 index d202715fae..0000000000 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/CapList.java +++ /dev/null @@ -1,324 +0,0 @@ -/*- - * ============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.sdc.common.datastructure; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * Thread Safe List with a cap for Max elements.<br> - * If an element would be inserted to the list and it is full, the oldest - * element will be taken out. - * - * @author mshitrit - * - * @param <T> - */ -public class CapList<T> implements List<T> { - private static final int DEFAULT_CAP = 1000; - private int cap; - private ReadWriteLock readWriteLock; - private List<T> innerList; - - public CapList() { - this(DEFAULT_CAP); - } - - public CapList(int cap) { - if (cap < 1) { - throw new RuntimeException("List Cap Must Be Positive"); - } - this.cap = cap; - innerList = new ArrayList<>(); - readWriteLock = new ReentrantReadWriteLock(); - } - - @Override - public boolean add(T e) { - try { - readWriteLock.writeLock().lock(); - boolean result = innerList.add(e); - removeExtras(); - return result; - - } finally { - readWriteLock.writeLock().unlock(); - } - - } - - private void removeExtras() { - while (innerList.size() > cap) { - innerList.remove(0); - } - } - - @Override - public void add(int index, T element) { - try { - readWriteLock.writeLock().lock(); - innerList.add(index, element); - } finally { - readWriteLock.writeLock().unlock(); - } - - } - - @Override - public boolean addAll(Collection<? extends T> c) { - try { - readWriteLock.writeLock().lock(); - boolean result = innerList.addAll(c); - removeExtras(); - return result; - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public boolean addAll(int index, Collection<? extends T> c) { - try { - readWriteLock.writeLock().lock(); - boolean result = innerList.addAll(index, c); - removeExtras(); - return result; - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public void clear() { - try { - readWriteLock.writeLock().lock(); - innerList.clear(); - } finally { - readWriteLock.writeLock().unlock(); - } - - } - - @Override - public boolean contains(Object o) { - try { - readWriteLock.readLock().lock(); - return innerList.contains(o); - - } finally { - readWriteLock.readLock().unlock(); - } - - } - - @Override - public boolean containsAll(Collection<?> c) { - try { - readWriteLock.readLock().lock(); - return innerList.containsAll(c); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public T get(int index) { - try { - readWriteLock.readLock().lock(); - return innerList.get(index); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public int indexOf(Object o) { - try { - readWriteLock.readLock().lock(); - return innerList.indexOf(o); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public boolean isEmpty() { - try { - readWriteLock.readLock().lock(); - return innerList.isEmpty(); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public Iterator<T> iterator() { - try { - readWriteLock.readLock().lock(); - return innerList.iterator(); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public int lastIndexOf(Object o) { - try { - readWriteLock.readLock().lock(); - return innerList.lastIndexOf(o); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public ListIterator<T> listIterator() { - try { - readWriteLock.readLock().lock(); - return innerList.listIterator(); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public ListIterator<T> listIterator(int index) { - try { - readWriteLock.readLock().lock(); - return innerList.listIterator(index); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public boolean remove(Object o) { - try { - readWriteLock.writeLock().lock(); - return innerList.remove(o); - - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public T remove(int index) { - try { - readWriteLock.writeLock().lock(); - return innerList.remove(index); - - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public boolean removeAll(Collection<?> c) { - try { - readWriteLock.writeLock().lock(); - return innerList.removeAll(c); - - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public boolean retainAll(Collection<?> c) { - try { - readWriteLock.writeLock().lock(); - return innerList.retainAll(c); - - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public T set(int index, T element) { - try { - readWriteLock.writeLock().lock(); - return innerList.set(index, element); - - } finally { - readWriteLock.writeLock().unlock(); - } - } - - @Override - public int size() { - try { - readWriteLock.readLock().lock(); - return innerList.size(); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public List<T> subList(int fromIndex, int toIndex) { - try { - readWriteLock.readLock().lock(); - return innerList.subList(fromIndex, toIndex); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public Object[] toArray() { - try { - readWriteLock.readLock().lock(); - return innerList.toArray(); - - } finally { - readWriteLock.readLock().unlock(); - } - } - - @Override - public <T> T[] toArray(T[] a) { - try { - readWriteLock.readLock().lock(); - return innerList.toArray(a); - - } finally { - readWriteLock.readLock().unlock(); - } - } - -} diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/data_structure/CapListTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/data_structure/CapListTest.java deleted file mode 100644 index 7aeb2ac70d..0000000000 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/data_structure/CapListTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * ============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.sdc.common.data_structure; - -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.junit.Test; -import org.openecomp.sdc.common.datastructure.CapList; - -public class CapListTest { - public enum LIST_ACTION { - Add, Remove, Size, Get - } - - @Test - public void testCap() { - List<Integer> testList = new CapList<>(10); - for (int i = 0; i < 100; i++) { - testList.add(i); - } - assertTrue(testList.size() == 10); - for (int i = 0; i < testList.size(); i++) { - assertTrue(testList.get(i) == (i + 90)); - } - } - - @Test - public void testThreadSafe() { - List<Integer> testList = new CapList<>(1000); - - ExecutorService executor = Executors.newFixedThreadPool(4); - for (int i = 0; i < 10; i++) { - Runnable worker; - // 0 - 4 - if (i < 5) { - worker = new ThreadWorker(i, LIST_ACTION.Add, testList); - } - // 5, 8 - else if (i == 5 || i == 8) { - worker = new ThreadWorker(i, LIST_ACTION.Remove, testList); - } - // 6 - else if (i == 6) { - worker = new ThreadWorker(i, LIST_ACTION.Size, testList); - } - // 7, 9 - else { - worker = new ThreadWorker(i, LIST_ACTION.Get, testList); - } - executor.execute(worker); - } - executor.shutdown(); - while (!executor.isTerminated()) { - } - assertTrue(testList.size() == 60); - } - - public static class ThreadWorker implements Runnable { - private LIST_ACTION action; - private List<Integer> list; - private Integer id; - - ThreadWorker(Integer id, LIST_ACTION action, List<Integer> list) { - this.action = action; - this.list = list; - this.id = id; - } - - @Override - public void run() { - for (int i = 0; i < 20; i++) { - threadNap(); - switch (action) { - case Add: - list.add(id * 100 + i); - break; - case Remove: { - int index = (int) (Math.random() * 10); - list.remove(index); - break; - } - case Get: - int index = (int) (Math.random() * 10); - Integer integer = list.get(index); - - break; - case Size: - int size = list.size(); - break; - } - } - - } - - private void threadNap() { - long napTime = (long) (Math.random() * 100); - try { - Thread.sleep(napTime); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } -} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java index ffaf7809c8..a31210a81a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java @@ -83,7 +83,9 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { if (entitlmentpoolElement.getRelations() == null) { entitlmentpoolElement.setRelations(new ArrayList<>()); } - entitlmentpoolElement.getRelations().addAll(epFromDb.get().getRelations()); + if (epFromDb.get().getRelations() != null) { + entitlmentpoolElement.getRelations().addAll(epFromDb.get().getRelations()); + } } zusammenAdaptor.saveElement(context,elementContext, entitlmentpoolElement, diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java index 03537a287b..f5d905cf35 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java @@ -74,14 +74,15 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { Optional<ElementInfo> lkgFromDb = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); - if(lkgFromDb.isPresent()) { + if (lkgFromDb.isPresent()) { - if( licenseKeyGroupElement.getRelations() == null) { + if (licenseKeyGroupElement.getRelations() == null) { licenseKeyGroupElement.setRelations(new ArrayList<>()); } - lkgFromDb.get().getRelations().forEach(relation -> - licenseKeyGroupElement.getRelations().add(relation)); + if (lkgFromDb.get().getRelations() != null) { + licenseKeyGroupElement.getRelations().addAll(lkgFromDb.get().getRelations()); + } } zusammenAdaptor.saveElement(context, elementContext, @@ -30,7 +30,7 @@ <artifact-generator-api.version>1.1.0-SNAPSHOT</artifact-generator-api.version> <artifact-generator-core.version>1.1.0-SNAPSHOT</artifact-generator-core.version> - <ecomp.version>1.1.0-SNAPSHOT</ecomp.version> + <ecomp.version>1.1.0</ecomp.version> <dox-common-lib.version>1.1.0-SNAPSHOT</dox-common-lib.version> <!-- Elastic Search mapper (reference the elastic search version actually). --> |