Skip to content

Commit

Permalink
Clean up after inspection
Browse files Browse the repository at this point in the history
Renaming CopperServices to CopperController + use of @RequestParam to use default values (spring alignment)
  • Loading branch information
Marc Cappelletti committed Jan 15, 2020
1 parent 91c6734 commit 1b5069d
Show file tree
Hide file tree
Showing 66 changed files with 617 additions and 893 deletions.
11 changes: 2 additions & 9 deletions src/main/java/ch/mno/copper/DataProvider.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package ch.mno.copper;

import java.util.List;

import ch.mno.copper.collect.StoryTask;
import ch.mno.copper.store.ValuesStore;
import ch.mno.copper.stories.data.Story;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Created by dutoitc on 25.02.2016.
*/
public interface DataProvider {

Set<Map.Entry<String, StoryTask>> getStoryTasks();

List<Story> getStories();

StoryTask getStoryTask(Story story);
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/ch/mno/copper/DataProviderImpl.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ch.mno.copper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ch.mno.copper.collect.StoryTask;
import ch.mno.copper.store.ValuesStore;
import ch.mno.copper.stories.StoriesFacade;
import ch.mno.copper.stories.data.Story;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Stories and values provider with cache.
* At each call, it will load newer stories from disk, remove older from cache
Expand All @@ -26,11 +25,6 @@ public DataProviderImpl(StoriesFacade storiesFacade, ValuesStore valuesStore) {
refreshStoryTasks();
}

@Override
public Set<Map.Entry<String, StoryTask>> getStoryTasks() {
return cachedStoryTasks.entrySet();
}

@Override
public List<Story> getStories() {
List<Story> stories = refreshStoryTasks();
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/ch/mno/copper/collect/BinaryCollectorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.BinaryConnector;
import ch.mno.copper.collect.connectors.ConnectorException;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Created by dutoitc on 07.02.2016.
*/
import ch.mno.copper.collect.connectors.BinaryConnector;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

public class BinaryCollectorWrapper extends AbstractCollectorWrapper {

private final List<CheckElement> checkElements;
Expand All @@ -28,13 +23,14 @@ public BinaryCollectorWrapper(List<CheckElement> checkElements) {
results = new HashMap<>(checkElements.size()*4/3+1);
}

@Override
public List<String> getAs() {
return checkElements.stream().map(e->e.as).collect(Collectors.toList());
}


@Override
public Map<String, String> execute() throws ConnectorException {
public Map<String, String> execute() {
for (CheckElement el: checkElements) {
boolean status;
switch (el.cmd) {
Expand All @@ -57,11 +53,11 @@ public Map<String, String> execute() throws ConnectorException {


@Override
public List<List<String>> execute2D() throws ConnectorException {
public List<List<String>> execute2D() {
Map<String, String> map = execute();
List<List<String>> lst = new ArrayList<>();
for (CheckElement entry: checkElements) {
lst.add(Arrays.asList(map.get(entry.as)));
lst.add(List.of(map.get(entry.as)));
}
return lst;
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/ch/mno/copper/collect/JmxCollector.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.ConnectorException;
import ch.mno.copper.collect.connectors.JmxConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.mno.copper.collect.connectors.JmxConnector;

/**
* Created by dutoitc on 29.01.2016.
Expand All @@ -26,8 +27,8 @@ public String read(JmxConnector jmxConnector, String objectName, String attribut
}


public static List<String> jmxQueryWithCreds(String serverUrl, String username, String password, List<JmxQuery> queries) throws ConnectorException {
List<String> results = new ArrayList(queries.size());
public static List<String> jmxQueryWithCreds(String serverUrl, String username, String password, List<JmxQuery> queries) {
List<String> results = new ArrayList<>(queries.size());
JmxConnector conn = null;
try {
if (username==null) {
Expand Down Expand Up @@ -57,10 +58,6 @@ public static List<String> jmxQueryWithCreds(String serverUrl, String username,
return results;
}

public static List<String> jmxQuery(String serverUrl, List<JmxQuery> queries) throws ConnectorException {
return jmxQueryWithCreds(serverUrl, null, null, queries);
}

public static class JmxQuery {

protected String objectName;
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/ch/mno/copper/collect/JmxCollectorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.ConnectorException;
import ch.mno.copper.helpers.NotImplementedException;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ch.mno.copper.helpers.NotImplementedException;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

/**
* Created by dutoitc on 07.02.2016.
*/
Expand All @@ -36,9 +35,9 @@ public List<String> getAs() {
}

@Override
public Map<String, String> execute() throws ConnectorException {
public Map<String, String> execute() {
List<String> values = JmxCollector.jmxQueryWithCreds(url, username, password, jmxQueries);
Map<String, String> map = new HashMap();
Map<String, String> map = new HashMap<>();
if (values.size()!=as.size()) {
throw new RuntimeException("Wrong values number, expected " + as.size() + ", got " + values.size());
}
Expand All @@ -49,7 +48,7 @@ public Map<String, String> execute() throws ConnectorException {
}

@Override
public List<List<String>> execute2D() throws ConnectorException {
public List<List<String>> execute2D() {
throw new NotImplementedException();
}

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/ch/mno/copper/collect/SocketCollectorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.ConnectorException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ch.mno.copper.collect.connectors.SocketConnector;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by dutoitc on 07.02.2016.
*/
Expand All @@ -34,19 +37,23 @@ public List<String> getAs() {


@Override
public Map<String, String> execute() throws ConnectorException {
SocketConnector sc = new SocketConnector(host, port, timeout_ms);
SocketConnector.CONNECTION_CHECK status = sc.checkConnection();
public Map<String, String> execute() {
SocketConnector.CONNECTION_CHECK status;
try (SocketConnector sc = new SocketConnector(host, port, timeout_ms)) {
status = sc.checkConnection();
}

Map<String, String> map = new HashMap<>(2);
map.put(as.get(0), status.toString());
return map;
}

@Override
public List<List<String>> execute2D() throws ConnectorException {
SocketConnector sc = new SocketConnector(host, port, timeout_ms);
SocketConnector.CONNECTION_CHECK status = sc.checkConnection();
public List<List<String>> execute2D() {
SocketConnector.CONNECTION_CHECK status;
try (SocketConnector sc = new SocketConnector(host, port, timeout_ms)) {
status = sc.checkConnection();
}

List<List<String>> lst = new ArrayList<>();
List<String> values = new ArrayList<>();
Expand Down
35 changes: 18 additions & 17 deletions src/main/java/ch/mno/copper/collect/WebCollector.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.HttpConnector;
import ch.mno.copper.collect.connectors.HttpResponseData;
import ch.mno.copper.collect.connectors.JmxConnector;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import net.minidev.json.JSONArray;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -23,9 +10,23 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by dutoitc on 29.01.2016.
*/
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;

import ch.mno.copper.collect.connectors.HttpConnector;
import ch.mno.copper.collect.connectors.HttpResponseData;
import ch.mno.copper.collect.connectors.JmxConnector;

public class WebCollector {

private static Logger LOG = LoggerFactory.getLogger(WebCollector.class);
Expand Down Expand Up @@ -82,7 +83,7 @@ public static List<String> query(String url, String username, String password, L
}

static List<String> extractValues(HttpResponseData<String> data, List<Pair<String, String>> valuesKept) {
List<String> results = new ArrayList(valuesKept.size());
List<String> results = new ArrayList<>(valuesKept.size());
for (Pair<String, String> value: valuesKept) {
String key = value.getKey();
if ("responseCode".equals(key)) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/ch/mno/copper/collect/WebCollectorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package ch.mno.copper.collect;

import ch.mno.copper.collect.connectors.ConnectorException;
import ch.mno.copper.helpers.NotImplementedException;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import ch.mno.copper.helpers.NotImplementedException;
import ch.mno.copper.helpers.SyntaxHelper;
import ch.mno.copper.stories.data.StoryGrammar;

/**
* Created by dutoitc on 07.02.2016.
*/
Expand All @@ -37,14 +37,15 @@ public WebCollectorWrapper(String url, String username, String password, List<Pa
}
}

@Override
public List<String> getAs() {
return as;
}

@Override
public Map<String, String> execute() throws ConnectorException {
public Map<String, String> execute() {
List<String> values = WebCollector.query(url, username, password, valuesKept);
Map<String, String> map = new HashMap();
Map<String, String> map = new HashMap<>();
if (values.size()!=valuesKept.size()) {
throw new RuntimeException("Wrong values number, expected " + valuesKept.size() + ", got " + values.size());
}
Expand All @@ -55,7 +56,7 @@ public Map<String, String> execute() throws ConnectorException {
}

@Override
public List<List<String>> execute2D() throws ConnectorException {
public List<List<String>> execute2D() {
throw new NotImplementedException();
}

Expand Down Expand Up @@ -100,7 +101,7 @@ public static WebCollectorWrapper buildCollector(StoryGrammar grammar, String st
while (matcher3.find()) {
String name1 = matcher3.group(1);
String name2 = matcher3.group(2);
valuesKept.add(new ImmutablePair(name1, name2));
valuesKept.add(new ImmutablePair<>(name1, name2));
}
return new WebCollectorWrapper(url, username, password, valuesKept);
}
Expand Down
Loading

0 comments on commit 1b5069d

Please sign in to comment.