}
if (!rslt.containsKey(schema.getProduct())) {
- rslt.put(schema.getProduct(), new HashSet<String>());
+ rslt.put(schema.getProduct(), new HashSet<>());
}
rslt.get(schema.getProduct()).add(schema.getService());
}
}
}
- for (String service : rslt.getOrDefault(product, new HashSet<String>())) {
+ for (String service : rslt.getOrDefault(product, new HashSet<>())) {
this.getResult().getRecordsMap().get("product").getValues().add(product);
this.getResult().getRecordsMap().get("service").getValues().add(service);
this.getResult().getRecordsMap().get("description").getValues().add(
*/
public class OnapCommandSchemaMerger {
- static Logger LOG = LoggerFactory.getLogger(OnapCommandSchemaMerger.class);
+ static Logger logger = LoggerFactory.getLogger(OnapCommandSchemaMerger.class);
- public static Map<String, ?> mergeSchemas(OnapCommand cmd) throws OnapCommandException {
- Map<String, Object> mergedResult = new LinkedHashMap<String, Object>();
+ public static Map<String, Object> mergeSchemas(OnapCommand cmd) throws OnapCommandException {
+ Map<String, Object> mergedResult = new LinkedHashMap<>();
for (String schema: cmd.getSchemas()) {
- Map<String , Object> schemaMap = (Map<String, Object>) OnapCommandSchemaLoader.validateSchemaVersion(schema, cmd.getSchemaVersion());
+ Map<String , Object> schemaMap = OnapCommandSchemaLoader.validateSchemaVersion(schema, cmd.getSchemaVersion());
mergeYamlMap(mergedResult, schemaMap);
}
public class OnapCommandExecutionStore {
private static Logger log = LoggerFactory.getLogger(OnapCommandExecutionStore.class);
- private static boolean storeReady = false;
- private static String REQUEST_ID = "requestId";
- private static String EXECUTION_ID = "executionId";
- private static String INPUT = "input";
- private static String STDOUT = "stdout";
- private static String STDERR = "stderr";
- private static String DEBUG = "debug";
- private static String IN_PROGRESS = "in-progress";
- private static String OUTPUT = "output";
- private static String ERROR = "error";
- private static String COMPLETED = "completed";
- private static String FAILED = "failed";
- private static String EXECUTIONID = "execution-id";
- private static String REQUESTID = "request-id";
+ private static boolean storeReady = false; // NOSONAR
+ private static final String REQUEST_ID = "requestId";
+ private static final String EXECUTION_ID = "executionId";
+ private static final String INPUT = "input";
+ private static final String STDOUT = "stdout";
+ private static final String STDERR = "stderr";
+ private static final String DEBUG = "debug";
+ private static final String IN_PROGRESS = "in-progress";
+ private static final String OUTPUT = "output";
+ private static final String ERROR = "error";
+ private static final String COMPLETED = "completed";
+ private static final String FAILED = "failed";
+ private static final String EXECUTIONID = "execution-id";
+ private static final String REQUESTID = "request-id";
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
public void add(String productVersion, String paramName, String paramValue) {
if (!paramCache.containsKey(productVersion)) {
- paramCache.put(productVersion, new HashMap<String, String>());
+ paramCache.put(productVersion, new HashMap<>());
}
paramCache.get(productVersion).put(paramName, paramValue);
* @return
*/
public static String replaceLineForSpecialValues(String lineSpl) {
- return replaceLineForSpecialValues(lineSpl, new HashMap<String, String>());
+ return replaceLineForSpecialValues(lineSpl, new HashMap<>());
}
/**
}
public static void copyParamsFrom(OnapCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
- copyParamsFrom(from, to, new HashMap<String, String>());
+ copyParamsFrom(from, to, new HashMap<>());
}
/**
public static class OpenInterfaceGrpcExecption extends Exception {
private static final long serialVersionUID = -8755636432217894246L;
- private int errorCode = -1;
-
+ private int errorCode = -1; //NOSONAR
public OpenInterfaceGrpcExecption(int errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
public static class OpenInterfaceGrpcTimeoutExecption extends OpenInterfaceGrpcExecption {
- private static int errorCode = 1;
+ private static final int ERROR_CODE = 1;
public OpenInterfaceGrpcTimeoutExecption(String message) {
- super(errorCode, message);
+ super(ERROR_CODE, message);
}
}
//Set the profile to current one
OnapCommandRegistrar.getRegistrar().setProfile(
profile,
- new ArrayList<String>(),
- new ArrayList<String>());
+ new ArrayList<>(),
+ new ArrayList<>());
//fill from profile
Map<String, String> cache= OnapCommandRegistrar.getRegistrar().getParamCache(product);
if (this.profile != null) {
OnapCommandRegistrar.getRegistrar().setProfile(
this.profile,
- new ArrayList<String>(),
- new ArrayList<String>());
+ new ArrayList<>(),
+ new ArrayList<>());
}
} catch (Exception e) {
this.print(e);
break;
} else if (OnapCliConstants.PARAM_INTERACTIVE_CLEAR.equalsIgnoreCase(line)) {
console.clearScreen();
- continue;
- }
- this.args = new ArrayList<>();
- this.args.addAll(Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN)));
+ } else {
+ this.args = new ArrayList<>();
+ this.args.addAll(Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN)));
if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) {
if (args.size() == 1) {
}
} else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) {
- try {
- this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion());
- this.print(OnapCli.getDirectiveHelp());
- } catch (OnapCommandException e) {
- this.print(e);
- }
-
- } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) {
- this.printVersion = true;
- handleVersion();
-
- } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_PROFILE)) {
- if (args.size() == 1) {
- this.print("Please use it in the form of 'profile <profile-name>'\n");
- this.print("Available profiles: ");
- this.print(OnapCommandRegistrar.getRegistrar().getUserProfiles().toString());
- } else {
- this.profile = args.get(1);
- handleProfile();
- }
+ this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion());
+ this.print(OnapCli.getDirectiveHelp());
+ } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) {
+ this.printVersion = true;
+ handleVersion();
+
+ } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_PROFILE)) {
+ if (args.size() == 1) {
+ this.print("Please use it in the form of 'profile <profile-name>'\n");
+ this.print("Available profiles: ");
+ this.print(OnapCommandRegistrar.getRegistrar().getUserProfiles().toString());
+ } else {
+ this.profile = args.get(1);
+ handleProfile();
+ }
- } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_SET)) {
- if (args.size() > 1) {
- String [] paramEntry = args.get(1).trim().split("=", 2);
- if (paramEntry.length == 2) {
- OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim());
+ } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_SET)) {
+ if (args.size() > 1) {
+ String[] paramEntry = args.get(1).trim().split("=", 2);
+ if (paramEntry.length == 2) {
+ OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim());
+ } else {
+ this.print("Please use it in the form of 'set <param-name>=<param-value>'");
+ }
} else {
- this.print("Please use it in the form of 'set <param-name>=<param-value>'");
+ this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString());
}
- } else {
- this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString());
- }
- } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) {
- if (args.size() > 1) {
- for (int i = 1; i <args.size(); i++) {
- OnapCommandRegistrar.getRegistrar().removeParamCache(args.get(i));
+ } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) {
+ if (args.size() > 1) {
+ for (int i = 1; i < args.size(); i++) {
+ OnapCommandRegistrar.getRegistrar().removeParamCache(args.get(i));
+ }
+ }
+ } else {
+ if (!(args.size() == 1 && args.get(0).trim().isEmpty())) {
+ this.setArgs(this.args.toArray(new String[]{}));
+ handleCommand();
}
}
- } else {
- if (args.size() == 1 && args.get(0).trim().isEmpty()) {
- //Ignore blanks // NOSONAR
- continue;
- }
-
- this.setArgs(this.args.toArray(new String [] {}));
- handleCommand();
}
}
} catch (IOException e) { // NOSONAR
case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
List<String> list = (ArrayList) valMap.get(key1);
- cmd.setSuccessStatusCodes(list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()));
+ cmd.setSuccessStatusCodes(list.stream().map(Integer::parseInt).collect(Collectors.toList()));
break;
case OnapCommandCmdConstants.PASS_CODE:
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.registrar.OnapCommandRegistrar;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import org.onap.cli.fw.http.error.OnapCommandLoginFailed;
/**
* Oclip Auth client helps to do login and logout.
*/
public class OnapCommandHttpAuthClient {
+ private static Logger logger = LoggerFactory.getLogger(OnapCommandHttpAuthClient.class); //NOSONAR
private OnapHttpCommand cmd = null;
private OnapHttpConnection http = null;
logout.execute();
- this.http.close();
+ try {
+ this.http.close();
+ } catch (IOException e) {
+ throw new OnapCommandLoginFailed("Exception when closing httpclient");
+ }
}
/**
import org.apache.http.annotation.Contract;
import org.apache.http.annotation.ThreadingBehavior;
import org.apache.http.client.CookieStore;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.client.protocol.ClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
-import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.cookie.Cookie;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.onap.cli.fw.http.error.OnapCommandHttpFailure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.impl.client.CloseableHttpClient;
+import javax.net.ssl.HostnameVerifier;
/**
* Helps to make http connection.<br>
*/
private static Logger log = LoggerFactory.getLogger(OnapHttpConnection.class);
- private HttpClient httpClient = null;
+ private CloseableHttpClient httpClient = null;
Map<String, String> mapCommonHeaders = new HashMap<> ();
SSLContext sslContext = SSLContext.getInstance(OnapCommandHttpConstants.SSLCONTEST_TLS);
sslContext.init(null, new TrustManager[] { new TrustAllX509TrustManager() },
new java.security.SecureRandom());
- X509HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier();
+ HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory>create()
.register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build();
CookieStore cookieStore = new BasicCookieStore();
updateInputFromCookies(input, cookieStore);
HttpContext localContext = new BasicHttpContext();
- localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
+ localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
this.initHttpClient(input.getUri().startsWith("https"));
return result;
}
- @SuppressWarnings("deprecation")
- public void close() {
+ public void close() throws IOException {
this.mapCommonHeaders.clear();
if (this.httpClient != null) {
- this.httpClient.getConnectionManager().shutdown();
+ this.httpClient.close();
}
}
validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
}
List<String> list = (ArrayList) valMap.get(key1);
- cmd.setSuccessStatusCodes(list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()));
+ cmd.setSuccessStatusCodes(list.stream().map(Integer::parseInt).collect(Collectors.toList()));
break;
case OnapCommandHttpConstants.RESULT_MAP:
}
@Test()
- public void httpUnSecuredCloseExceptionTest() throws OnapCommandHttpFailure {
+ public void httpUnSecuredCloseExceptionTest() throws IOException {
inp.setMethod("other");
con = new OnapHttpConnection();
con.close();
assertEquals("203::0x3001::Failed", failed.getMessage());
}
+ @Test
+ public void oclipCommandLoginFailedTest3() {
+ OnapCommandLoginFailed failed = new OnapCommandLoginFailed("Failed");
+
+ assertEquals("0x4001::Login failed, Failed", failed.getMessage());
+ }
+
@Test
public void oclipCommandLoginFailedTest1() {
OnapCommandLoginFailed failed = new OnapCommandLoginFailed(new Exception("Failed"));
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Vector;
/**
* Oclip snmp Command.
ResponseEvent responseEvent = snmp.send(getPDU(PDU.GET, oidStrArr), getTarget(), null);
if ( responseEvent != null) {
if (responseEvent.getResponse().getErrorStatus() == PDU.noError) {
- Vector<? extends VariableBinding> variableBindings = responseEvent.
+ List<? extends VariableBinding> variableBindings = responseEvent.
getResponse().getVariableBindings();
variableBindings.stream().forEach(varBinding -> { //NOSONAR
String key = getKeyForValue(varBinding.getOid().toString());
}
private static String printTabs() {
- StringBuffer spaces = new StringBuffer();
+ StringBuilder spaces = new StringBuilder();
for (int i=0; i < nTab; i++) {
spaces.append(" ");
}