diff options
author | wejs <maciej.wejs@nokia.com> | 2018-01-25 12:41:33 +0100 |
---|---|---|
committer | wejs <maciej.wejs@nokia.com> | 2018-02-01 12:18:18 +0100 |
commit | 46150f8ef3cf60716cb5d02eab8e595052c628f5 (patch) | |
tree | d2e309bd164e1445a3749c19d3233486714973d6 /appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src | |
parent | 03f48c7ea7de11d7c7d0933a0438afa4280e3bf7 (diff) |
Sonar fixes in "appc-netconf-adapter-bundle"
Change-Id: Ib5842a5f43c9437fee464e9a35e3120a11d1c6b1
Issue-ID: APPC-494
Signed-off-by: wejs <maciej.wejs@nokia.com>
Diffstat (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src')
20 files changed, 115 insertions, 143 deletions
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java index 70438d7da..33bf33112 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java @@ -26,9 +26,6 @@ package org.onap.appc.adapter.netconf; import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl; import org.onap.ccsdk.sli.core.dblib.DbLibService; -import org.onap.appc.i18n.Msg; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -43,10 +40,6 @@ public class AppcNetconfAdapterActivator implements BundleActivator { private ServiceRegistration reporterRegistration = null; private ServiceRegistration factoryRegistration = null; private ServiceRegistration dbRegistration = null; - /** - * The logger to be used - */ - private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class); /** * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start @@ -71,17 +64,13 @@ public class AppcNetconfAdapterActivator implements BundleActivator { */ NetconfClientFactory clientFactory = new NetconfClientFactory(); factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null); - NetconfDataAccessService DAService = new NetconfDataAccessServiceImpl(); + NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl(); //set dblib service - DbLibService dblibSvc = null; ServiceReference sref = context.getServiceReference(DbLibService.class.getName()); - dblibSvc = (DbLibService)context.getService(sref); - DAService.setDbLibService(dblibSvc); + dataAccessService.setDbLibService((DbLibService)context.getService(sref)); /////////////////////////////////// - factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null); + factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null); } - - //logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter"); } /** @@ -122,9 +111,4 @@ public class AppcNetconfAdapterActivator implements BundleActivator { dbRegistration = null; } } - - public String getName() { - return "APPC NETCONF adapter"; - } - } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/MockOperationalStateValidatorImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/MockOperationalStateValidatorImpl.java index 079ae76a4..f29336280 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/MockOperationalStateValidatorImpl.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/MockOperationalStateValidatorImpl.java @@ -26,8 +26,8 @@ package org.onap.appc.adapter.netconf; import org.onap.appc.exceptions.APPCException; - public class MockOperationalStateValidatorImpl implements OperationalStateValidator { + @Override public VnfType getVnfType() { return VnfType.MOCK; @@ -35,8 +35,8 @@ public class MockOperationalStateValidatorImpl implements OperationalStateValida @Override public String getConfigurationFileName() { - String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); - return configFileName; + return OperationalStateValidatorFactory.configuration + .getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); } @Override diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfClientFactory.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfClientFactory.java index 45c8fb0ed..0ce6c4bc5 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfClientFactory.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfClientFactory.java @@ -30,7 +30,7 @@ import org.onap.appc.adapter.netconf.odlconnector.NetconfClientRestconfImpl; public class NetconfClientFactory { - public NetconfClient GetNetconfClient(NetconfClientType type){ + public NetconfClient getNetconfClient(NetconfClientType type){ if(type==NetconfClientType.RESTCONF) { return new NetconfClientRestconfImpl(); diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfDataAccessService.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfDataAccessService.java index f831541da..a8607a5c9 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfDataAccessService.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfDataAccessService.java @@ -49,7 +49,7 @@ public interface NetconfDataAccessService { * @return * @throws DataAccessException */ - String retrieveConfigFileName(String xmlID) throws DataAccessException; + String retrieveConfigFileName(String xmlID); /** * @@ -58,7 +58,7 @@ public interface NetconfDataAccessService { * @return * @throws DataAccessException */ - boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws DataAccessException; + boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails); /** * @@ -67,8 +67,7 @@ public interface NetconfDataAccessService { * @return * @throws DataAccessException */ - boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws - DataAccessException; + boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails); /** * @@ -79,7 +78,6 @@ public interface NetconfDataAccessService { * @return * @throws DataAccessException */ - boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws - DataAccessException; + boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText); } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidator.java index ffa3862e8..db3a8ef7e 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidator.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidator.java @@ -28,8 +28,9 @@ import org.onap.appc.exceptions.APPCException; public interface OperationalStateValidator { + public static final String CONFIG_FILE_PROPERTY_SUFFIX = "-CONFIG_FILE"; public VnfType getVnfType(); public String getConfigurationFileName(); public void validateResponse(String response) throws APPCException; - final public static String CONFIG_FILE_PROPERTY_SUFFIX = "-CONFIG_FILE"; + } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidatorFactory.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidatorFactory.java index 37e96917d..d6d34ba13 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidatorFactory.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidatorFactory.java @@ -31,8 +31,10 @@ import org.onap.appc.configuration.ConfigurationFactory; public class OperationalStateValidatorFactory { protected static final Configuration configuration = ConfigurationFactory.getConfiguration(); + protected OperationalStateValidatorFactory() {} + public static OperationalStateValidator getOperationalStateValidator(String vnfType) { - VnfType vnfTypeEnum = null; + VnfType vnfTypeEnum; try { vnfTypeEnum = VnfType.getVnfType(vnfType); } catch (IllegalArgumentException e) { diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java index 4bb5ab238..ebe69c851 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java @@ -41,6 +41,7 @@ import java.util.*; public class VNFOperationalStateValidatorImpl implements OperationalStateValidator { private static final String OPERATIONAL_STATE_ELEMENT_NAME = "operationalState"; + @Override public VnfType getVnfType() { return VnfType.VNF; @@ -48,8 +49,9 @@ public class VNFOperationalStateValidatorImpl implements OperationalStateValidat @Override public String getConfigurationFileName() { - String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); - configFileName = configFileName == null? "VnfGetOperationalStates" : configFileName; + String configFileName = OperationalStateValidatorFactory.configuration + .getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); + configFileName = configFileName == null ? "VnfGetOperationalStates" : configFileName; return configFileName; } @@ -58,54 +60,46 @@ public class VNFOperationalStateValidatorImpl implements OperationalStateValidat if(StringUtils.isEmpty(response)) { throw new APPCException("empty response"); } - - boolean isValid = false; - String errorMsg = "unexpected response"; try { - List<Map.Entry> operationalStateList = getOperationalStateList(response); - if(operationalStateList != null && !operationalStateList.isEmpty()) { - for (Map.Entry stateEntry : operationalStateList) { - if(!((String)stateEntry.getValue()).equalsIgnoreCase("ENABLED")){ - errorMsg = "at least one "+OPERATIONAL_STATE_ELEMENT_NAME+" is not in valid satae. "+operationalStateList.toString(); - isValid = false; - break; - }else{ - isValid =true; - } - } - }else { - errorMsg = "response without any "+OPERATIONAL_STATE_ELEMENT_NAME+" element"; + List<Map.Entry> operationalStateList = getOperationalStateList(response).orElseThrow(() -> + new APPCException("response without any "+OPERATIONAL_STATE_ELEMENT_NAME+" element")); + + if(operationalStateList.stream().anyMatch(this::isNotEnabled)) { + throw new APPCException("at least one "+OPERATIONAL_STATE_ELEMENT_NAME+" is not in valid state. " + +operationalStateList.toString()); } - } catch (Exception e ) { - isValid = false; - errorMsg = e.toString(); + + } catch (Exception e) { + throw new APPCException(e); } - if(!isValid) throw new APPCException(errorMsg); } - private static List<Map.Entry> getOperationalStateList(String xmlText) throws IOException, ParserConfigurationException, SAXException { + private boolean isNotEnabled(Map.Entry stateEntry) { + return !("ENABLED").equalsIgnoreCase((String)stateEntry.getValue()); + } + + private static Optional<List<Map.Entry>> getOperationalStateList(String xmlText) throws IOException, ParserConfigurationException, SAXException { List<Map.Entry> entryList = null; - if(StringUtils.isNotEmpty(xmlText)) { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Document document = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8"))); - if(document != null) { - Element rootElement = document.getDocumentElement(); - NodeList nodeList = rootElement.getElementsByTagName(OPERATIONAL_STATE_ELEMENT_NAME); - if (nodeList != null && nodeList.getLength() > 0) { - for (int i = 0; i < nodeList.getLength(); i++) { - Node node = nodeList.item(i); - String text = node.getTextContent(); - String id = getElementID(node); - entryList = (entryList == null) ? new ArrayList<Map.Entry>() : entryList; - Map.Entry entry = new AbstractMap.SimpleEntry<String, String>(id, text); - entryList.add(entry); - } + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8"))); + + if(document != null) { + Element rootElement = document.getDocumentElement(); + NodeList nodeList = rootElement.getElementsByTagName(OPERATIONAL_STATE_ELEMENT_NAME); + if (nodeList != null && nodeList.getLength() > 0) { + entryList = new ArrayList<>(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + String text = node.getTextContent(); + String id = getElementID(node); + Map.Entry entry = new AbstractMap.SimpleEntry<>(id, text); + entryList.add(entry); } } } - return entryList; + return Optional.ofNullable(entryList); } private static String getElementID(Node node) { diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter.java index 2d8c6f417..bb2a333ea 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter.java @@ -71,26 +71,17 @@ public class NetconfAdapter { final NetconfMessage message = new NetconfMessage(); final byte[] buf = new byte[1024]; - //int readByte = 1; // Read data with timeout - Callable<Boolean> readTask = new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - int c; - while ((c = in.read(buf)) > 0) { - if (c > 0) { - message.append(buf, 0, c); - if (message.isCompleted()) { - break; - } - } + Callable<Boolean> readTask = () -> { + int c; + while ((c = in.read(buf)) > 0) { + message.append(buf, 0, c); + if (message.isCompleted()) { + break; } - - if (c < 0) { - return false; - } - return true; } + + return c >= 0; }; Future<Boolean> future = executor.submit(readTask); @@ -101,7 +92,7 @@ public class NetconfAdapter { throw new IOException(e); } - if (status == false) { + if (!status) { throw new IOException("Failed to read netconf message"); } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfConstMessages.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfConstMessages.java index c7ad9bc50..897788e1e 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfConstMessages.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfConstMessages.java @@ -26,8 +26,10 @@ package org.onap.appc.adapter.netconf.internal; public class NetconfConstMessages { + private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; + public static final String CAPABILITIES_START = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + XML_HEADER + "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <capabilities>\n"; @@ -39,7 +41,7 @@ public class NetconfConstMessages { "</hello>"; public static final String GET_RUNNING_CONFIG = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + XML_HEADER + "<rpc message-id=\"1\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <get-config>\n" + " <source>\n" + @@ -49,8 +51,10 @@ public class NetconfConstMessages { "</rpc>"; public static final String CLOSE_SESSION = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + XML_HEADER + "<rpc message-id=\"terminateConnection\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <close-session/>\n" + "</rpc>"; + + private NetconfConstMessages() {} } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java index 6ed181d1d..7a6848b53 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java @@ -41,18 +41,21 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService { private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class); + private String schema; + + private DbLibService dbLibService; + + @Override public void setSchema(String schema) { this.schema = schema; } - private String schema; - + @Override public void setDbLibService(DbLibService service) {dbLibService = service;} - private DbLibService dbLibService; @Override - public String retrieveConfigFileName(String xmlID) throws DataAccessException { + public String retrieveConfigFileName(String xmlID) { String fileContent = ""; String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " + @@ -76,8 +79,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService { } @Override - public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws - DataAccessException { + public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) { boolean recordFound = false; String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + @@ -105,8 +107,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService { } @Override - public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) - throws DataAccessException { + public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) { ConnectionDetails connDetails = new ConnectionDetails(); if(this.retrieveConnectionDetails(vnfType, connDetails)) { @@ -119,8 +120,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService { } @Override - public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) - throws DataAccessException { + public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) { String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+ Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+ Constants.REQUEST_ID_FIELD_NAME+","+ diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfMessage.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfMessage.java index 700a51b9f..40e00964d 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfMessage.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfMessage.java @@ -47,8 +47,9 @@ class NetconfMessage { } } - void append(byte[] bytes, int start, int end) { + void append(byte[] bytes, int start, int finish) { boolean eomFound = false; + int end = finish; for(int i = start; i < end; i++) { if(bytes[i] == EOM.charAt(eomNotch)) { // advance notch @@ -76,7 +77,7 @@ class NetconfMessage { } boolean isCompleted() { - return (text != null); + return text != null; } byte[] getFrame() { diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/JSchLogger.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/JSchLogger.java index 37bb3b2f2..ffcd9033e 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/JSchLogger.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/JSchLogger.java @@ -58,6 +58,8 @@ public class JSchLogger implements com.jcraft.jsch.Logger { case com.jcraft.jsch.Logger.FATAL: LOG.error(message); break; + default: + break; } } } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java index 7b9d7a4ae..c60fbbd1f 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java @@ -75,17 +75,9 @@ public class NetconfClientJsch implements NetconfClient { session.connect(SESSION_CONNECT_TIMEOUT); session.setTimeout(10000); - try { -// session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!! - channel = session.openChannel("subsystem"); - ((ChannelSubsystem)channel).setSubsystem("netconf"); - netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream()); - channel.connect(CHANNEL_CONNECT_TIMEOUT); - hello(connectionDetails.getCapabilities()); - } catch(Exception e) { - disconnect(); - throw e; - } + + createConnection(connectionDetails); + } catch(Exception e) { String message = EELFResourceManager.format(Msg.CANNOT_ESTABLISH_CONNECTION, host, String.valueOf(port), username); throw new APPCException(message, e); @@ -138,6 +130,20 @@ public class NetconfClientJsch implements NetconfClient { } } + private void createConnection(NetconfConnectionDetails connectionDetails) throws APPCException { + try { +// session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!! + channel = session.openChannel("subsystem"); + ((ChannelSubsystem)channel).setSubsystem("netconf"); + netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream()); + channel.connect(CHANNEL_CONNECT_TIMEOUT); + hello(connectionDetails.getCapabilities()); + } catch(Exception e) { + disconnect(); + throw new APPCException(e); + } + } + private void hello(List<String> capabilities) throws IOException { String helloIn = netconfAdapter.receiveMessage(); if(helloIn == null) { diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java index bc89551a8..d2d90194c 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java @@ -42,8 +42,8 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe private NetconfConnectionDetails connectionDetails; - //constructor public NetconfClientRestconfImpl(){ + //constructor } //restconf client impl diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter.java index cb20cbdb5..1d1c8f142 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter.java @@ -26,7 +26,6 @@ package org.onap.appc.adapter.netconf.internal; import org.junit.Assert; import org.junit.Test; -import org.onap.appc.adapter.netconf.internal.NetconfAdapter; import java.io.IOException; import java.io.PipedInputStream; diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestGetRunningConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestGetRunningConfig.java index b559bc749..09281f44a 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestGetRunningConfig.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestGetRunningConfig.java @@ -24,13 +24,11 @@ package org.onap.appc.adapter.netconf.jsch; +import org.onap.appc.adapter.netconf.NetconfConnectionDetails; + import java.util.Collections; import java.util.List; -import org.onap.appc.adapter.netconf.NetconfConnectionDetails; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.exceptions.APPCException; - public class TestGetRunningConfig { private static final String HOST = "192.168.1.2"; @@ -39,7 +37,7 @@ public class TestGetRunningConfig { private static final int PORT = 830; private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>"); - public static void main(String[] args) throws APPCException { + public static void main(String[] args) { try { NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); connectionDetails.setHost(HOST); diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfig.java index 809625333..8750473d1 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfig.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfig.java @@ -24,13 +24,11 @@ package org.onap.appc.adapter.netconf.jsch; +import org.onap.appc.adapter.netconf.NetconfConnectionDetails; + import java.util.Collections; import java.util.List; -import org.onap.appc.adapter.netconf.NetconfConnectionDetails; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.exceptions.APPCException; - public class TestModifyConfig { private static final String HOST = "192.168.1.2"; @@ -64,7 +62,7 @@ public class TestModifyConfig { " </edit-config>\n" + "</rpc>"; - public static void main(String[] args) throws APPCException { + public static void main(String[] args) { try { NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); connectionDetails.setHost(HOST); diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigMock.java index 915721d51..31dee091c 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigMock.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigMock.java @@ -24,13 +24,11 @@ package org.onap.appc.adapter.netconf.jsch; +import org.onap.appc.adapter.netconf.NetconfConnectionDetails; + import java.util.Collections; import java.util.List; -import org.onap.appc.adapter.netconf.NetconfConnectionDetails; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.exceptions.APPCException; - public class TestModifyConfigMock { private static final String HOST = "192.168.1.2"; @@ -64,7 +62,7 @@ public class TestModifyConfigMock { " </edit-config>\n" + "</rpc>"; - public static void main(String[] args) throws APPCException { + public static void main(String[] args) { try { NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); connectionDetails.setHost(HOST); diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java index 83e62bc9f..1001c012f 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java @@ -24,13 +24,11 @@ package org.onap.appc.adapter.netconf.jsch; +import org.onap.appc.adapter.netconf.NetconfConnectionDetails; + import java.util.Collections; import java.util.List; -import org.onap.appc.adapter.netconf.NetconfConnectionDetails; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.exceptions.APPCException; - public class TestModifyConfigRouterMock { private static final String HOST = "10.147.27.50"; // yuma netconf simulator @@ -66,7 +64,7 @@ public class TestModifyConfigRouterMock { " </edit-config>\n" + "</rpc>\n"; - public static void main(String[] args) throws APPCException { + public static void main(String[] args) { try { NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); connectionDetails.setHost(HOST); diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestOperationalStates.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestOperationalStates.java index 263dd5a8f..a8c9e28b4 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestOperationalStates.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestOperationalStates.java @@ -24,13 +24,11 @@ package org.onap.appc.adapter.netconf.jsch; +import org.onap.appc.adapter.netconf.NetconfConnectionDetails; + import java.util.Collections; import java.util.List; -import org.onap.appc.adapter.netconf.NetconfConnectionDetails; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.exceptions.APPCException; - public class TestOperationalStates { private static final String HOST = "192.168.1.2"; @@ -62,7 +60,7 @@ public class TestOperationalStates { " </get>\n" + "</rpc>"; - public static void main(String[] args) throws APPCException { + public static void main(String[] args) { try { NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); connectionDetails.setHost(HOST); |