aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/main/java
diff options
context:
space:
mode:
authorwejs <maciej.wejs@nokia.com>2018-02-07 17:19:59 +0100
committerMichael Lando <ml636r@att.com>2018-02-08 15:33:30 +0000
commiteae2ba3f5ccfb20a899262562bd91129b6d53423 (patch)
treec850ada6af230865f7e713326be75b1325bd7302 /asdctool/src/main/java
parent2d2e0b503f915a81ae9a02dfa3afac3de369efde (diff)
Sonar fixes in ArtifactValidatorExecuter
Blocker sonar issues fix and CheckStyle formating corrections. Change-Id: I0882722f66bb0bb80b6eb85fe11657d10fe86d37 Issue-ID: APPC-525 Signed-off-by: wejs <maciej.wejs@nokia.com>
Diffstat (limited to 'asdctool/src/main/java')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java212
1 files changed, 102 insertions, 110 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
index 4b9764d2d5..7f85d9d972 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
@@ -1,5 +1,6 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
+import fj.data.Either;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -30,116 +31,107 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import fj.data.Either;
+public class ArtifactValidatorExecuter {
+
+ @Autowired
+ protected TitanDao titanDao;
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ private static Logger log = LoggerFactory.getLogger(ArtifactValidatorExecuter.class.getName());
+
+ protected String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type,
+ Map<GraphPropertyEnum, Object> hasProps) {
+
+ Map<String, List<Component>> result = new HashMap<>();
+ Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
+ if (resultsEither.isRight()) {
+ System.out.println("getVerticesToValidate failed " + resultsEither.right().value());
+ return result;
+ }
+ System.out.println("getVerticesToValidate: " + resultsEither.left().value().size() + " vertices to scan");
+ List<GraphVertex> componentsList = resultsEither.left().value();
+ componentsList.forEach(vertex -> {
+ String ivariantUuid = (String)vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
+ if (!result.containsKey(ivariantUuid)) {
+ result.put(ivariantUuid, new ArrayList<>());
+ }
+ List<Component> compList = result.get(ivariantUuid);
+
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreArtifacts(false);
+
+ Either<Component, StorageOperationStatus> toscaElement
+ = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
+ if (toscaElement.isRight()) {
+ System.out.println("getVerticesToValidate: failed to find element"
+ + vertex.getUniqueId() + " staus is" + toscaElement.right().value());
+ } else {
+ compList.add(toscaElement.left().value());
+ }
+ });
+ return result;
+ }
+
+ public boolean validate(Map<String, List<Component>> vertices) {
+ boolean result = true;
+ long time = System.currentTimeMillis();
+ String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_" + time + ".csv";
+
+ try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ writer.write("name, UUID, invariantUUID, state, version\n");
+ Collection<List<Component>> collection = vertices.values();
+ for (List<Component> compList: collection) {
+ Set<String> artifactEsId = new HashSet<>();
+ for (Component component: compList) {
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ Optional<ArtifactDefinition> op = toscaArtifacts.values()
+ .stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny();
+ if (op.isPresent()) {
+ result = false;
+ writeModuleResultToFile(writer, compList);
+ writer.flush();
+ break;
+ } else {
+ artifactEsId.addAll(toscaArtifacts.values()
+ .stream().map(ArtifactDefinition::getEsId).collect(Collectors.toList()));
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.info("Failed to fetch vf resources ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ }
+ return result;
+ }
-public class ArtifactValidatorExecuter{
-
- @Autowired
- protected TitanDao titanDao;
-
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
- private static Logger log = LoggerFactory.getLogger(ArtifactValidatorExecuter.class.getName());
-
- protected String name;
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
-
-
- public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type, Map<GraphPropertyEnum, Object> hasProps){
- Map<String, List<Component>> result = new HashMap<>();
- Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
- if (resultsEither.isRight()) {
- System.out.println("getVerticesToValidate failed "+ resultsEither.right().value());
- return result;
- }
- System.out.println("getVerticesToValidate: "+resultsEither.left().value().size()+" vertices to scan");
- List<GraphVertex> componentsList = resultsEither.left().value();
- componentsList.forEach(vertex -> {
- String ivariantUuid = (String)vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
- if(!result.containsKey(ivariantUuid)){
- List<Component> compList = new ArrayList<Component>();
- result.put(ivariantUuid, compList);
- }
- List<Component> compList = result.get(ivariantUuid);
-
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreArtifacts(false);
-
- Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
- if (toscaElement.isRight()) {
- System.out.println("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
- }else{
- compList.add(toscaElement.left().value());
- }
-
- });
-
- return result;
- }
-
- public boolean validate( Map<String, List<Component>> vertices) {
- boolean result = true;
- long time = System.currentTimeMillis();
- String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_"+ time + ".csv";
- Writer writer = null;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
- writer.write("name, UUID, invariantUUID, state, version\n");
- Collection<List<Component>> collection = vertices.values();
- for(List<Component> compList: collection ){
- Set<String> artifactEsId = new HashSet<>();
- for(Component component: compList ){
- Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
- Optional<ArtifactDefinition> op = toscaArtifacts.values().
- stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny();
- if(op.isPresent()){
- result = false;
- writeModuleResultToFile(writer, compList);
- writer.flush();
- break;
- }else{
- artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId).collect(Collectors.toList())) ;
- }
- }
-
- }
-
- } catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
- return false;
- } finally {
- titanDao.commit();
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return result;
- }
-
- private void writeModuleResultToFile(Writer writer, List<Component> components) {
- try {
- // "service name, service id, state, version
- for(Component component: components ){
- StringBuffer sb = new StringBuffer(component.getName());
- sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID()).append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
-
- sb.append("\n");
- writer.write(sb.toString());
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ private void writeModuleResultToFile(Writer writer, List<Component> components) {
+ try {
+ // "service name, service id, state, version
+ for (Component component: components ) {
+ StringBuilder sb = new StringBuilder(component.getName());
+ sb.append(",").append(component.getUniqueId())
+ .append(",").append(component.getInvariantUUID())
+ .append(",").append(component.getLifecycleState())
+ .append(",").append(component.getVersion())
+ .append("\n");
+ writer.write(sb.toString());
+ }
+ } catch (IOException e) {
+ log.debug("Cannot write module result to file", e);
+ }
+ }
}