@Override public void resetModel(Resource resource) throws ResourceException { resource.setModel(new ComputerSystem()); ((ComputerSystem) resource.getModel()) .setName(resource.getResourceDescriptor().getInformation().getName()); if (isALogicalRouter(resource)) ((ComputerSystem) resource.getModel()) .setElementName(resource.getResourceDescriptor().getInformation().getName()); }
@Override public void bootstrap(Resource resource) throws ResourceException { VCPENetworkModel model = createEmptyModel(resource); if (((VCPENetworkDescriptor) resource.getResourceDescriptor()).getvCPEModel() != null) { // load model from the one persisted in the descriptor model = loadModelFromDescriptor((VCPENetworkDescriptor) resource.getResourceDescriptor()); } resource.setModel(model); }
@Override public void resetModel(Resource resource) throws ResourceException { resource.setModel(createEmptyModel(resource)); }
@Override public void revertBootstrap(Resource resource) throws ResourceException { resource.setModel(oldModel); }
@Test public void MakeRemoveConnectionsResourceTest() throws Exception { ResourceDescriptor resourceDescriptor = ResourceHelper.newResourceDescriptorProteus("roadm"); /* create resource */ Resource resource = (Resource) repository.createResource(resourceDescriptor); Assert.assertNotNull(resource.getResourceIdentifier()); Assert.assertNotNull(resource.getResourceDescriptor()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); Assert.assertNull(resource.getProfile()); Assert.assertFalse(repository.listResources().isEmpty()); // add protocol for resource createProtocolForResource(resource.getResourceIdentifier().getId()); /* start resource */ repository.startResource(resource.getResourceIdentifier().getId()); Assert.assertFalse(resource.getCapabilities().isEmpty()); Assert.assertNotNull(resource.getModel()); // Assert.assertNotNull(resource.getProfile()); IConnectionsCapability connections = (IConnectionsCapability) resource.getCapabilityByInterface(IConnectionsCapability.class); if (connections == null) Assert.fail("Capability not found"); IQueueManagerCapability queueCapability = (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class); if (queueCapability == null) Assert.fail("Capability not found"); /* checking model */ // TODO CHECK NEW MODEL CONFIG /* refresh connection */ // Response resp = (Response) connections.sendMessage(ActionConstants.REFRESHCONNECTIONS, null); // List<ActionResponse> responses = (List<ActionResponse>) // queueCapability.sendMessage(QueueManagerConstants.EXECUTE, null); // // Assert.assertTrue(responses.size() == 2); // ActionResponse actionResponse = responses.get(0); // Assert.assertEquals(ActionConstants.REFRESHCONNECTIONS, actionResponse.getActionID()); // for (Response response : actionResponse.getResponses()) { // Assert.assertTrue(response.getStatus() == Response.Status.OK); // } // // List<IAction> queue = (List<IAction>) // queueCapability.sendMessage(QueueManagerConstants.GETQUEUE, null); // Assert.assertTrue(queue.size() == 0); OpticalSwitchFactory opticalSwitchFactory = new OpticalSwitchFactory(); resource.setModel(opticalSwitchFactory.newPedrosaProteusOpticalSwitch()); /* make connection */ FiberConnection connectionRequest = newMakeConnectionParams((ProteusOpticalSwitch) resource.getModel()); connections.makeConnection(connectionRequest); QueueResponse queueResponse = queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); boolean foundAndOk = false; for (ActionResponse response : queueResponse.getResponses()) { if (response.getActionID().equals(ActionConstants.MAKECONNECTION)) { if (response.getStatus() == STATUS.OK) { foundAndOk = true; for (Response subresponse : response.getResponses()) { Assert.assertTrue(subresponse.getStatus() == Response.Status.OK); } } } } Assert.assertTrue(foundAndOk); List<IAction> queue = (List<IAction>) queueCapability.getActions(); Assert.assertTrue(queue.size() == 0); /* checking model */ Assert.assertNotNull( getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel())); // checking for model intern details is in action tests /* remove connection */ connections.removeConnection(connectionRequest); queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); foundAndOk = false; for (ActionResponse response : queueResponse.getResponses()) { if (response.getActionID().equals(ActionConstants.REMOVECONNECTION)) { if (response.getStatus() == STATUS.OK) { foundAndOk = true; for (Response subresponse : response.getResponses()) { Assert.assertTrue(subresponse.getStatus() == Response.Status.OK); } } } } Assert.assertTrue(foundAndOk); queue = (List<IAction>) queueCapability.getActions(); Assert.assertTrue(queue.size() == 0); /* checking model */ Assert.assertNull( getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel())); /* stop resource */ repository.stopResource(resource.getResourceIdentifier().getId()); Assert.assertNotNull(resource.getResourceIdentifier()); Assert.assertNotNull(resource.getResourceDescriptor()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); // Assert.assertNull(resource.getProfile()); Assert.assertFalse(repository.listResources().isEmpty()); /* remove resource */ createProtocolForResource(resource.getResourceIdentifier().getId()); repository.removeResource(resource.getResourceIdentifier().getId()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); Assert.assertNull(resource.getProfile()); // Assert.assertTrue(repository.listResources().isEmpty()); }