import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.openecomp.sdc.asdctool.main.ArtifactUUIDFixMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
}
- if (false == leftValue.equals(rightValue)) {
+ if (!leftValue.equals(rightValue)) {
log.trace("The value of key {} is differnet between properties. {} vs {}",key,leftValue,rightValue);
return false;
}
public static void setProperties(Element element, Map<String, Object> properties) {
- if (properties != null && false == properties.isEmpty()) {
+ if (properties != null && !properties.isEmpty()) {
Object[] propertyKeyValues = new Object[properties.size() * 2];
int i = 0;
@org.springframework.stereotype.Component("artifactUuidFix")
public class ArtifactUuidFix {
+
+ private static final String MIGRATION1707_ARTIFACT_UUID_FIX = "Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ";
+
+ private static final String FAILED_TO_FETCH_VF_RESOURCES = "Failed to fetch vf resources ";
+ private static final String UTF8 = "utf-8";
+
@Autowired
private TitanDao titanDao;
}
if ("service_vf".equals(runMode) || "fix".equals(runMode)) {
log.info("Mode {}. Find problem VFs", runMode);
- if (fetchVf(serviceList, vfLst, time) == false) {
+ if (!fetchVf(serviceList, vfLst, time)) {
log.info("Mode {}. Find problem VFs finished with failure", runMode);
return false;
}
}
if ("fix".equals(runMode) || "fix_only_services".equals(runMode)) {
log.info("Mode {}. Start fix", runMode);
- if (fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca) == false) {
+ if (!fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca)) {
log.info("Mode {}. Fix finished with failure", runMode);
return false;
}
private boolean fetchFaultVf(String fixComponent, List<Resource> vfLst, long time) {
log.info("Find fault VF ");
String fileName = "fault_" + time + ".csv";
- try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
writer.write("vf name, vf id, state, version\n");
Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
}
} catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
+ log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
return false;
} finally {
titanDao.commit();
return true;
}
String fileName = "problemVf_" + time + ".csv";
- try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
writer.write("vf name, vf id, state, version, example service name\n");
Set<String> vfIds = new HashSet<>();
for (Service service : serviceList) {
private boolean fetchServices(String fixServices, List<Service> serviceList, long time) {
log.info("Find problem Services {}", fixServices);
String fileName = "problemService_" + time + ".csv";
- try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
writer.write("service name, service id, state, version\n");
Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
long time = System.currentTimeMillis();
String fileName = "FailedGenerateTosca" + "_" + time + ".csv";
- try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
writer.write("componentType, name, version, UID, UUID, invariantUUID, state\n");
List<Component> failedList = new ArrayList<>();
}
if (isAddToGroup) {
log.debug(
- "Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ",
+ MIGRATION1707_ARTIFACT_UUID_FIX,
group.getName(), correctArtifactId, correctArtifactUUID);
group.getArtifacts().add(correctArtifactId);
if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
}
} else {
log.debug(
- "Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ",
+ MIGRATION1707_ARTIFACT_UUID_FIX,
group.getName(), correctArtifactId, correctArtifactUUID);
Set<String> tmpSet = new HashSet<>(group.getGroupInstanceArtifacts());
tmpSet.add(correctArtifactId);
}
if (isAddToGroup) {
log.debug(
- "Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ",
+ MIGRATION1707_ARTIFACT_UUID_FIX,
group.getName(), correctArtifactId, correctArtifactUUID);
group.getArtifacts().add(correctArtifactId);
if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
});
} catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
+ log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
} finally {
titanDao.commit();
boolean result = true;
long time = System.currentTimeMillis();
String fileName = name + "_" + time + ".csv";
- try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
writer.write("name, UUID, invariantUUID, state, version\n");
for (Map.Entry<String, List<Component>> entry : vertices.entrySet()) {
List<Component> compList = entry.getValue();
}
} catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
+ log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
return false;
} finally {
titanDao.commit();
}
}
}
- if (importToCassandra && !importToCassndra(files)) {
- return false;
- }
- return true;
+ return !importToCassandra || importToCassndra(files);
}
private boolean initEsClient() {
public class GraphMLConverter {
- private static Logger log = Logger.getLogger(GraphMLConverter.class.getName());
+ private static final String FROM_VERTEX = "fromVertex={}";
+
+ private static final String STORAGE_BACKEND = "storage.backend";
+
+ private static final String INMEMORY = "inmemory";
+
+ private static final String CLOSE_FILE_OUTPUT_STREAM_FAILED = "close FileOutputStream failed - {}";
+
+ private static final String EXPORT_GRAPH = "exportGraph.";
+
+ private static final String DOT_JSON = ".json";
+
+ private static final String EXPORTED_FILE = "Exported file=";
+
+ private static final String NODE_LABEL = "nodeLabel";
+
+ private static Logger log = Logger.getLogger(GraphMLConverter.class.getName());
private Gson gson = new Gson();
List<ImmutablePair<String, String>> propertiesCriteriaToDelete = new ArrayList<>();
ImmutablePair<String, String> immutablePair1 = new ImmutablePair<>("healthcheckis", "GOOD");
- ImmutablePair<String, String> immutablePair2 = new ImmutablePair<>("nodeLabel", "user");
- ImmutablePair<String, String> immutablePair3 = new ImmutablePair<>("nodeLabel",
+ ImmutablePair<String, String> immutablePair2 = new ImmutablePair<>(NODE_LABEL, "user");
+ ImmutablePair<String, String> immutablePair3 = new ImmutablePair<>(NODE_LABEL,
"resourceCategory");
- ImmutablePair<String, String> immutablePair4 = new ImmutablePair<>("nodeLabel",
+ ImmutablePair<String, String> immutablePair4 = new ImmutablePair<>(NODE_LABEL,
"serviceCategory");
propertiesCriteriaToDelete.add(immutablePair1);
return false;
}
- System.out.println("Exported file=" + result);
+ System.out.println(EXPORTED_FILE + result);
} catch (Exception e) {
log.info("export graph failed -{}" , e);
return false;
result = exportGraphMl(graph, outputDirectory);
- System.out.println("Exported file=" + result);
+ System.out.println(EXPORTED_FILE + result);
} catch (Exception e) {
log.info("export exportGraphMl failed - {}" , e);
return null;
return false;
}
- System.out.println("Exported file=" + result);
+ System.out.println(EXPORTED_FILE + result);
} catch (Exception e) {
log.info("find Error In Json Graph failed - {}" , e);
return false;
String result = null;
- String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".json";
+ String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + DOT_JSON;
OutputStream out = null;
try {
out.close();
}
} catch (IOException e) {
- log.info("close FileOutputStream failed - {}" , e);
+ log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
}
}
return result;
public String exportGraphMl(TitanGraph graph, String outputDirectory) {
String result = null;
- String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
+ String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + ".graphml";
try {
try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
is.close();
}
} catch (IOException e) {
- log.info("close FileOutputStream failed - {}" , e);
+ log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
}
}
String result = null;
- String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".json";
+ String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + DOT_JSON;
OutputStream out = null;
try {
vertexTo = edge.inVertex();
BaseConfiguration conf = new BaseConfiguration();
- conf.setProperty("storage.backend", "inmemory");
+ conf.setProperty(STORAGE_BACKEND, INMEMORY);
TitanGraph openGraph = Utils.openGraph(conf);
TitanVertex addVertexFrom = openGraph.addVertex();
Edge addEdge = addVertexFrom.addEdge(edge.label(), addVertexTo);
Utils.setProperties(addEdge, Utils.getProperties(edge));
- log.info("fromVertex={}", Utils.getProperties(vertexFrom));
+ log.info(FROM_VERTEX, Utils.getProperties(vertexFrom));
log.info("toVertex={}", Utils.getProperties(vertexTo));
log.info("edge={} {} ",edge.label(),Utils.getProperties(edge));
} catch (Exception e) {
log.info("run Edge Scan failed - {}" , e);
- log.error("fromVertex={}", Utils.getProperties(vertexFrom));
+ log.error(FROM_VERTEX, Utils.getProperties(vertexFrom));
log.error("toVertex={}", Utils.getProperties(vertexTo));
log.error("edge={} {} ",edge.label(),Utils.getProperties(edge));
if (!iterator2.hasNext()) {
BaseConfiguration conf = new BaseConfiguration();
- conf.setProperty("storage.backend", "inmemory");
+ conf.setProperty(STORAGE_BACKEND, INMEMORY);
TitanGraph openGraph = Utils.openGraph(conf);
TitanVertex addVertexFrom = openGraph.addVertex();
Utils.setProperties(addVertexFrom, Utils.getProperties(vertex));
- log.info("fromVertex={}", Utils.getProperties(addVertexFrom));
+ log.info(FROM_VERTEX, Utils.getProperties(addVertexFrom));
GraphSONWriter create = GraphSONWriter.build().create();
create.writeGraph(out, openGraph);
;
BaseConfiguration conf = new BaseConfiguration();
- conf.setProperty("storage.backend", "inmemory");
+ conf.setProperty(STORAGE_BACKEND, INMEMORY);
for (NodeTypeEnum nodeTypeEnum : NodeTypeEnum.values()) {
removeNodesByLabel(graph, nodeTypeEnum.getName());
}
out.close();
}
} catch (IOException e) {
- log.info("close FileOutputStream failed - {}" , e);
+ log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
}
}
return result;
List<Map<String, Object>> users = new ArrayList<>();
String result = null;
- String outputFile = outputDirectory + File.separator + "users." + System.currentTimeMillis() + ".json";
+ String outputFile = outputDirectory + File.separator + "users." + System.currentTimeMillis() + DOT_JSON;
FileWriter fileWriter = null;
try {
fileWriter.close();
}
} catch (IOException e) {
- log.info("close FileOutputStream failed - {}" , e);
+ log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
}
}
return result;
return false;
}
- System.out.println("Exported file=" + result);
+ System.out.println(EXPORTED_FILE + result);
} catch (Exception e) {
log.info("export Users failed - {}" , e);
return false;
// Parse ML file
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File(mlFileLocation);
- Document document = (Document) builder.build(xmlFile);
+ Document document = builder.build(xmlFile);
// XLS data file name
String outputFile = mlFileLocation.replace(".graphml", ".xls");
private TitanGraph openGraph(String titanFileLocation) {
- TitanGraph graph = TitanFactory.open(titanFileLocation);
-
- return graph;
-
+ return TitanFactory.open(titanFileLocation);
+
}
}
*/
public class RestUtils {
- final static String DELETE_PRODUCT = "http://%s:%s/sdc2/rest/v1/catalog/products/%s";
+ static final String DELETE_PRODUCT = "http://%s:%s/sdc2/rest/v1/catalog/products/%s";
private static Logger log = Logger.getLogger(RestUtils.class.getName());