2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.scheduledtasks;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
25 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
26 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
27 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.exception.ResponseFormat;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
35 import java.util.HashMap;
36 import java.util.List;
39 @Component("componentsCleanBusinessLogic")
40 public class ComponentsCleanBusinessLogic extends BaseBusinessLogic {
43 private ResourceBusinessLogic resourceBusinessLogic;
46 private ServiceBusinessLogic serviceBusinessLogic;
48 private static final Logger log = LoggerFactory.getLogger(ComponentsCleanBusinessLogic.class);
50 public Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponents(List<NodeTypeEnum> componentsToClean) {
52 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents = new HashMap<NodeTypeEnum, Either<List<String>, ResponseFormat>>();
54 log.trace("start cleanComponents");
55 for (NodeTypeEnum type : componentsToClean) {
58 processDeletionForType(cleanedComponents, NodeTypeEnum.Resource, resourceBusinessLogic);
61 processDeletionForType(cleanedComponents, NodeTypeEnum.Service, serviceBusinessLogic);
64 log.debug("{} component type does not have cleaning method defined", type);
69 log.trace("end cleanComponents");
70 return cleanedComponents;
73 private void processDeletionForType(Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents, NodeTypeEnum type, ComponentBusinessLogic componentBusinessLogic) {
74 Either<List<String>, ResponseFormat> deleteMarkedResources = componentBusinessLogic.deleteMarkedComponents();
75 if (deleteMarkedResources.isRight()) {
76 log.debug("failed to clean deleted components of type {}. error: {}", type, deleteMarkedResources.right().value().getFormattedMessage());
78 if (log.isDebugEnabled()) {
79 StringBuilder sb = new StringBuilder("list of deleted components - type " + type + ": ");
80 for (String id : deleteMarkedResources.left().value()) {
81 sb.append(id).append(", ");
83 log.debug(sb.toString());
86 cleanedComponents.put(type, deleteMarkedResources);