@Test public void testDeployNonCodedAdapter() throws Exception { DeviceAdapterId adapter = getDeviceAdapterId(); ArgumentCaptor<DeviceAdapter> devAdapter = ArgumentCaptor.forClass(DeviceAdapter.class); String adapterId = adapter.getType() + AdapterSpecificConstants.DASH + adapter.getInterfaceVersion() + AdapterSpecificConstants.DASH + adapter.getModel() + AdapterSpecificConstants.DASH + adapter.getVendor(); CommonFileUtil.unpackToSpecificDirectory(m_dir + STAGED_AREA_ARCHIVE_PATH, m_dir + File.separator + adapterId); m_nonCodedAdapterService.deployAdapter(adapterId, m_subsystem, this.getClass(), m_dir, m_dir, m_devInterface); verify(m_adapterManager).deploy(devAdapter.capture(), eq(m_subsystem), eq(this.getClass()), eq(m_devInterface)); DeviceAdapter actualAdapter = devAdapter.getValue(); assertEquals(m_expectedAdapterId, actualAdapter.getDeviceAdapterId()); assertEquals(3, actualAdapter.getSupportedFeatures().size()); assertEquals(1, actualAdapter.getSupportedDevations().size()); assertEquals(5, actualAdapter.getCapabilities().size()); assertEquals(3, actualAdapter.getRevisions().size()); assertEquals(m_expectedDefaultXml, IOUtils.toString(new ByteArrayInputStream(actualAdapter.getDefaultXmlBytes())).trim()); }
@Override public void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea, String ipfixStagingArea, DeviceInterface deviceInterface) throws Exception { String destDirname = stagingArea + File.separator + deviceAdapterId; String deviceXmlPath = destDirname + ADAPTER_XML_PATH; String yangXmlPath = destDirname + File.separator + YANG_LIB_FILE; String supportedFeaturesPath = destDirname + DEFAULT_FEATURES_PATH; String supportedDeviationPath = destDirname + DEFAULT_DEVIATIONS_PATH; String defaultXml = destDirname + DEFAULT_CONFIG_XML_PATH; String ipfixIeMappingFile = destDirname + File.separator + DEFAULT_IPFIX_MAPPING_FILE_PATH; File deviceFile = new File(deviceXmlPath); List<String> modulePaths = new ArrayList<>(); Map<URL, InputStream> moduleStream = CommonFileUtil.buildModuleStreamMap(destDirname, modulePaths); VariantFileUtils.copyYangLibFiles(yangXmlPath, destDirname + SLASH + MODEL); try (InputStream deviceXmlInputStream = new FileInputStream(deviceFile); InputStream supportedFeaturesInputStream = new FileInputStream(supportedFeaturesPath); InputStream supportedDeviationInputStream = new FileInputStream(supportedDeviationPath); InputStream defaultXmlStream = new FileInputStream(defaultXml)) { Set<QName> features = getAdapterFeaturesFromFile(supportedFeaturesInputStream); Map<QName, Set<QName>> deviations = getAdapterDeviationsFromFile(supportedDeviationInputStream); byte[] defaultXmlbytes = IOUtils.toByteArray(defaultXmlStream); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceXml(deviceXmlInputStream) .setModuleStream(moduleStream) .setSupportedFeatures(features) .setSupportedDeviations(deviations) .setDefaultxmlBytes(defaultXmlbytes) .build(); adapter.init(); moveIpfixMappingFileToStagingArea(ipfixIeMappingFile, ipfixStagingArea, adapter.getDeviceAdapterId()); m_manager.deploy(adapter, subSystem, klass, deviceInterface); } }
NonCodedAdapterServiceImpl implements NonCodedAdapterService { @Override public void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea, String ipfixStagingArea, DeviceInterface deviceInterface) throws Exception { String destDirname = stagingArea + File.separator + deviceAdapterId; String deviceXmlPath = destDirname + ADAPTER_XML_PATH; String yangXmlPath = destDirname + File.separator + YANG_LIB_FILE; String supportedFeaturesPath = destDirname + DEFAULT_FEATURES_PATH; String supportedDeviationPath = destDirname + DEFAULT_DEVIATIONS_PATH; String defaultXml = destDirname + DEFAULT_CONFIG_XML_PATH; String ipfixIeMappingFile = destDirname + File.separator + DEFAULT_IPFIX_MAPPING_FILE_PATH; File deviceFile = new File(deviceXmlPath); List<String> modulePaths = new ArrayList<>(); Map<URL, InputStream> moduleStream = CommonFileUtil.buildModuleStreamMap(destDirname, modulePaths); VariantFileUtils.copyYangLibFiles(yangXmlPath, destDirname + SLASH + MODEL); try (InputStream deviceXmlInputStream = new FileInputStream(deviceFile); InputStream supportedFeaturesInputStream = new FileInputStream(supportedFeaturesPath); InputStream supportedDeviationInputStream = new FileInputStream(supportedDeviationPath); InputStream defaultXmlStream = new FileInputStream(defaultXml)) { Set<QName> features = getAdapterFeaturesFromFile(supportedFeaturesInputStream); Map<QName, Set<QName>> deviations = getAdapterDeviationsFromFile(supportedDeviationInputStream); byte[] defaultXmlbytes = IOUtils.toByteArray(defaultXmlStream); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceXml(deviceXmlInputStream) .setModuleStream(moduleStream) .setSupportedFeatures(features) .setSupportedDeviations(deviations) .setDefaultxmlBytes(defaultXmlbytes) .build(); adapter.init(); moveIpfixMappingFileToStagingArea(ipfixIeMappingFile, ipfixStagingArea, adapter.getDeviceAdapterId()); m_manager.deploy(adapter, subSystem, klass, deviceInterface); } } }
NonCodedAdapterServiceImpl implements NonCodedAdapterService { @Override public void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea, String ipfixStagingArea, DeviceInterface deviceInterface) throws Exception { String destDirname = stagingArea + File.separator + deviceAdapterId; String deviceXmlPath = destDirname + ADAPTER_XML_PATH; String yangXmlPath = destDirname + File.separator + YANG_LIB_FILE; String supportedFeaturesPath = destDirname + DEFAULT_FEATURES_PATH; String supportedDeviationPath = destDirname + DEFAULT_DEVIATIONS_PATH; String defaultXml = destDirname + DEFAULT_CONFIG_XML_PATH; String ipfixIeMappingFile = destDirname + File.separator + DEFAULT_IPFIX_MAPPING_FILE_PATH; File deviceFile = new File(deviceXmlPath); List<String> modulePaths = new ArrayList<>(); Map<URL, InputStream> moduleStream = CommonFileUtil.buildModuleStreamMap(destDirname, modulePaths); VariantFileUtils.copyYangLibFiles(yangXmlPath, destDirname + SLASH + MODEL); try (InputStream deviceXmlInputStream = new FileInputStream(deviceFile); InputStream supportedFeaturesInputStream = new FileInputStream(supportedFeaturesPath); InputStream supportedDeviationInputStream = new FileInputStream(supportedDeviationPath); InputStream defaultXmlStream = new FileInputStream(defaultXml)) { Set<QName> features = getAdapterFeaturesFromFile(supportedFeaturesInputStream); Map<QName, Set<QName>> deviations = getAdapterDeviationsFromFile(supportedDeviationInputStream); byte[] defaultXmlbytes = IOUtils.toByteArray(defaultXmlStream); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceXml(deviceXmlInputStream) .setModuleStream(moduleStream) .setSupportedFeatures(features) .setSupportedDeviations(deviations) .setDefaultxmlBytes(defaultXmlbytes) .build(); adapter.init(); moveIpfixMappingFileToStagingArea(ipfixIeMappingFile, ipfixStagingArea, adapter.getDeviceAdapterId()); m_manager.deploy(adapter, subSystem, klass, deviceInterface); } } NonCodedAdapterServiceImpl(AdapterManager manager); }
NonCodedAdapterServiceImpl implements NonCodedAdapterService { @Override public void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea, String ipfixStagingArea, DeviceInterface deviceInterface) throws Exception { String destDirname = stagingArea + File.separator + deviceAdapterId; String deviceXmlPath = destDirname + ADAPTER_XML_PATH; String yangXmlPath = destDirname + File.separator + YANG_LIB_FILE; String supportedFeaturesPath = destDirname + DEFAULT_FEATURES_PATH; String supportedDeviationPath = destDirname + DEFAULT_DEVIATIONS_PATH; String defaultXml = destDirname + DEFAULT_CONFIG_XML_PATH; String ipfixIeMappingFile = destDirname + File.separator + DEFAULT_IPFIX_MAPPING_FILE_PATH; File deviceFile = new File(deviceXmlPath); List<String> modulePaths = new ArrayList<>(); Map<URL, InputStream> moduleStream = CommonFileUtil.buildModuleStreamMap(destDirname, modulePaths); VariantFileUtils.copyYangLibFiles(yangXmlPath, destDirname + SLASH + MODEL); try (InputStream deviceXmlInputStream = new FileInputStream(deviceFile); InputStream supportedFeaturesInputStream = new FileInputStream(supportedFeaturesPath); InputStream supportedDeviationInputStream = new FileInputStream(supportedDeviationPath); InputStream defaultXmlStream = new FileInputStream(defaultXml)) { Set<QName> features = getAdapterFeaturesFromFile(supportedFeaturesInputStream); Map<QName, Set<QName>> deviations = getAdapterDeviationsFromFile(supportedDeviationInputStream); byte[] defaultXmlbytes = IOUtils.toByteArray(defaultXmlStream); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceXml(deviceXmlInputStream) .setModuleStream(moduleStream) .setSupportedFeatures(features) .setSupportedDeviations(deviations) .setDefaultxmlBytes(defaultXmlbytes) .build(); adapter.init(); moveIpfixMappingFileToStagingArea(ipfixIeMappingFile, ipfixStagingArea, adapter.getDeviceAdapterId()); m_manager.deploy(adapter, subSystem, klass, deviceInterface); } } NonCodedAdapterServiceImpl(AdapterManager manager); @Override void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea,
                              String ipfixStagingArea, DeviceInterface deviceInterface); @Override void unDeployAdapter(String type, String interfaceVersion, String model, String vendor); @Override DeviceAdapterId getNonCodedAdapterId(String adapterArchiveFileName, String deviceXmlpath); }
NonCodedAdapterServiceImpl implements NonCodedAdapterService { @Override public void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea, String ipfixStagingArea, DeviceInterface deviceInterface) throws Exception { String destDirname = stagingArea + File.separator + deviceAdapterId; String deviceXmlPath = destDirname + ADAPTER_XML_PATH; String yangXmlPath = destDirname + File.separator + YANG_LIB_FILE; String supportedFeaturesPath = destDirname + DEFAULT_FEATURES_PATH; String supportedDeviationPath = destDirname + DEFAULT_DEVIATIONS_PATH; String defaultXml = destDirname + DEFAULT_CONFIG_XML_PATH; String ipfixIeMappingFile = destDirname + File.separator + DEFAULT_IPFIX_MAPPING_FILE_PATH; File deviceFile = new File(deviceXmlPath); List<String> modulePaths = new ArrayList<>(); Map<URL, InputStream> moduleStream = CommonFileUtil.buildModuleStreamMap(destDirname, modulePaths); VariantFileUtils.copyYangLibFiles(yangXmlPath, destDirname + SLASH + MODEL); try (InputStream deviceXmlInputStream = new FileInputStream(deviceFile); InputStream supportedFeaturesInputStream = new FileInputStream(supportedFeaturesPath); InputStream supportedDeviationInputStream = new FileInputStream(supportedDeviationPath); InputStream defaultXmlStream = new FileInputStream(defaultXml)) { Set<QName> features = getAdapterFeaturesFromFile(supportedFeaturesInputStream); Map<QName, Set<QName>> deviations = getAdapterDeviationsFromFile(supportedDeviationInputStream); byte[] defaultXmlbytes = IOUtils.toByteArray(defaultXmlStream); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceXml(deviceXmlInputStream) .setModuleStream(moduleStream) .setSupportedFeatures(features) .setSupportedDeviations(deviations) .setDefaultxmlBytes(defaultXmlbytes) .build(); adapter.init(); moveIpfixMappingFileToStagingArea(ipfixIeMappingFile, ipfixStagingArea, adapter.getDeviceAdapterId()); m_manager.deploy(adapter, subSystem, klass, deviceInterface); } } NonCodedAdapterServiceImpl(AdapterManager manager); @Override void deployAdapter(String deviceAdapterId, SubSystem subSystem, Class klass, String stagingArea,
                              String ipfixStagingArea, DeviceInterface deviceInterface); @Override void unDeployAdapter(String type, String interfaceVersion, String model, String vendor); @Override DeviceAdapterId getNonCodedAdapterId(String adapterArchiveFileName, String deviceXmlpath);  }