AdapterManagerImpl implements AdapterManager { @Override public void deploy(DeviceAdapter adapter, SubSystem subSystem, Class klass, DeviceInterface deviceInterface) { LOGGER.info("Deploying the adapter: " + adapter.getDeviceAdapterId().toString()); try { m_readWriteLockService.executeWithWriteLock(new WriteLockTemplate<Void>() { @Override public Void execute() throws LockServiceException { DeviceAdapterId adapterId = new DeviceAdapterId(adapter.getType(), adapter.getInterfaceVersion(), adapter.getModel(), adapter.getVendor()); String componentId = getComponentId(adapter); AdapterContext adapterContext = new AdapterContext(m_readWriteLockService, deviceInterface); try { verifyIfMaxAllowedAdaptersInstalled(adapterId, adapter); m_standardModelRegistrator.setOldIdentities(SchemaRegistryUtil.getAllIdentities( adapterContext.getSchemaRegistry())); deployAdapter(adapter, adapterContext, componentId, subSystem, klass); if ((ENABLE_FACTORY_GARMENT_TAG_RETRIEVAL) && (!adapter.getModel().equalsIgnoreCase(STANDARD) && !adapter.getVendor().equalsIgnoreCase(BBF))) { computeFactoryGarmentTag(adapter, adapterContext); } m_adapterContextRegistry.putIfAbsent(adapterId, adapterContext); m_adapterMap.putIfAbsent(adapterId, adapter); EditConfigRequest editReq = validateDefaultXmlAndGenerateEditConfig(adapter, adapterContext); m_defaultConfigReqMap.putIfAbsent(adapterId, editReq); adapter.setLastUpdateTime(DateTime.now().toDateTime(DateTimeZone.UTC)); m_standardModelRegistrator.onDeployed(adapter, adapterContext); } catch (Exception e) { try { AdapterUtils.logErrorToFile(e.toString(), adapter); } catch (IOException ex) { LOGGER.error(String.format(ex.getMessage())); } m_adapterContextRegistry.remove(adapterId); m_adapterMap.remove(adapterId); m_defaultConfigReqMap.remove(adapterId); LOGGER.error("Error while deploying adapter: " + adapter.getDeviceAdapterId().toString(), e); throw new RuntimeException("Error while deploying adapter", e); } return null; } }); } catch (LockServiceException e) { throw new RuntimeException(e); } } AdapterManagerImpl(ModelNodeDataStoreManager dataStoreManager, ReadWriteLockService readWriteLockService,
                              EntityRegistry entityRegistry, EventAdmin eventAdmin, StandardModelRegistrator standardModelRegistrator); @Override void deploy(DeviceAdapter adapter, SubSystem subSystem, Class klass, DeviceInterface deviceInterface); @Override void undeploy(DeviceAdapter adapter); @Override int getAdapterSize(); @Override DeviceAdapter getDeviceAdapter(DeviceAdapterId adapterId); @Override AdapterContext getAdapterContext(DeviceAdapterId adapterId); @Override Collection<DeviceAdapter> getAllDeviceAdapters(); @Override EditConfigRequest getEditRequestForAdapter(DeviceAdapterId adapterId); FactoryGarmentTag getFactoryGarmentTag(DeviceAdapter adapter); static boolean ENABLE_FACTORY_GARMENT_TAG_RETRIEVAL; }
@Test public void testScenarioWhenDeafultConfigIncorrect() throws IOException { List<String> cap = new ArrayList<>(); cap.add("capability1-adapter2"); cap.add("capability2-adapter2"); byte[] m_defaultConfigIncorrect = IOUtils.toByteArray(getClass().getResourceAsStream("/model/default-config-incorrect.xml")); DeviceAdapter adapter = AdapterBuilder.createAdapterBuilder() .setDeviceAdapterId(new DeviceAdapterId("DPU", "1.0", "4LT", "VENDOR")) .setModuleStream(getStreamMap()) .setCaps(cap) .setDeviceXml(m_inputStream) .setDefaultxmlBytes(m_defaultConfigIncorrect) .setSupportedDeviations(CommonFileUtil.getAdapterDeviationsFromFile(getInputStream("model/supported-deviations.txt"))) .setSupportedFeatures(CommonFileUtil.getAdapterFeaturesFromFile(getInputStream("model/supported-features.txt"))) .build(); adapter.setStdAdapterIntVersion("2.0"); try { m_adapterManager.deploy(m_stdAdapterv2, m_subSystem, getClass(), m_deviceInterface); m_adapterManager.deploy(adapter, m_subSystem, getClass(), m_deviceInterface); } catch (Exception e) { assertEquals("Error while deploying adapter", e.getMessage()); String message = e.getCause().getMessage(); assertTrue(message.contains("ValidationException")); assertTrue(message.contains("errorMessage=An unexpected element leaf-not-present is present")); assertTrue(message.contains("errorTag=unknown-element")); assertTrue(message.contains("errorSeverity=error")); assertTrue(message.contains("errorType=application")); } m_defaultConfigIncorrect = IOUtils.toByteArray(getClass().getResourceAsStream("/model/default-config-incorrect2.xml")); adapter = AdapterBuilder.createAdapterBuilder() .setDeviceAdapterId(new DeviceAdapterId("DPU", "1.0", "4LT", "VENDOR")) .setModuleStream(getStreamMap()) .setCaps(cap) .setDeviceXml(m_inputStream) .setDefaultxmlBytes(m_defaultConfigIncorrect) .setSupportedDeviations(CommonFileUtil.getAdapterDeviationsFromFile(getInputStream("model/supported-deviations.txt"))) .setSupportedFeatures(CommonFileUtil.getAdapterFeaturesFromFile(getInputStream("model/supported-features.txt"))) .build(); adapter.setStdAdapterIntVersion("2.0"); try { m_adapterManager.deploy(adapter, m_subSystem, getClass(), m_deviceInterface); } catch (Exception e) { assertEquals("Error while deploying adapter", e.getMessage()); String message = e.getCause().getMessage(); assertTrue(message.contains("Failed to parse default-config.xml from the adapter")); assertTrue(message.contains("The element type \"if:leaf-not-present\" must be terminated by the matching end-tag")); } }