Search in sources :

Example 76 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project lispflowmapping by opendaylight.

the class SubnetDataProcessor method create.

/**
 * Method adds the newly created subnet as an EID prefix to the
 * MappingService. The subnet's network UUID is used as the key for this EID
 * prefix.
 */
@Override
public void create(Subnet subnet) {
    // TODO update for multi-tenancy
    LOG.info("Neutron Subnet Created request : Subnet name: " + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
    LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
    // Determine the IANA code for the subnet IP version
    // Default is set to IPv4 for neutron subnets
    final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
    try {
        final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
        if (lfmdb == null) {
            LOG.debug("lfmdb is null!!!");
            return;
        }
        final AddKeyInput addKeyInput = LispUtil.buildAddKeyInput(eid, subnet.getUuid().getValue());
        final Future<RpcResult<Void>> result = lfmdb.addKey(addKeyInput);
        final Boolean isSuccessful = result.get().isSuccessful();
        if (isSuccessful) {
            LOG.debug("Neutron Subnet Added to MapServer : Subnet name: " + subnet.getName() + " EID Prefix: " + subnet.getCidr() + " Key: " + subnet.getUuid());
        }
        LOG.info("Neutron Subnet Created request : Subnet name: " + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : " + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) AddKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) OdlMappingserviceService(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService) ExecutionException(java.util.concurrent.ExecutionException)

Example 77 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project lispflowmapping by opendaylight.

the class MappingServiceTest method getMappingTest_withNullMapRecord.

/**
 * Tests {@link MappingService#getMapping} method with null MappingRecord.
 */
@Test
public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
    // input
    final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "No mapping was found in the mapping database").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
    final RpcError errorResult = result.get().getErrors().iterator().next();
    assertEquals(1, result.get().getErrors().size());
    assertEquals(error.getMessage(), errorResult.getMessage());
    assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
    assertEquals(error.getCause(), errorResult.getCause());
    assertEquals(error.getErrorType(), errorResult.getErrorType());
    assertEquals(error.getInfo(), errorResult.getInfo());
    assertEquals(error.getTag(), errorResult.getTag());
    assertEquals(error.getSeverity(), errorResult.getSeverity());
    assertEquals(rpc.getResult(), result.get().getResult());
    assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
Also used : GetMappingInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder) GetMappingInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Test(org.junit.Test)

Example 78 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project lispflowmapping by opendaylight.

the class MappingServiceTest method updateKeyTest_withNullMapAuthkey.

/**
 * Tests {@link MappingService#updateKey} method with null MappingAuthkey.
 */
@Test
public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
    final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
    // input
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing", "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
    final RpcError errorResult = result.get().getErrors().iterator().next();
    assertEquals(1, result.get().getErrors().size());
    assertEquals(error.getMessage(), errorResult.getMessage());
    assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
    assertEquals(error.getCause(), errorResult.getCause());
    assertEquals(error.getErrorType(), errorResult.getErrorType());
    assertEquals(error.getInfo(), errorResult.getInfo());
    assertEquals(error.getTag(), errorResult.getTag());
    assertEquals(error.getSeverity(), errorResult.getSeverity());
    assertEquals(rpc.getResult(), result.get().getResult());
    assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
Also used : UpdateKeyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInputBuilder) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput) Test(org.junit.Test)

Example 79 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project lispflowmapping by opendaylight.

the class MappingServiceTest method getKeyTest_withNullMappingAuthkey.

/**
 * Tests {@link MappingService#getKey} method with null MappingAuthkey.
 */
@Test
public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
    // input
    final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
    final RpcError errorResult = result.get().getErrors().iterator().next();
    assertEquals(1, result.get().getErrors().size());
    assertEquals(error.getMessage(), errorResult.getMessage());
    assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
    assertEquals(error.getCause(), errorResult.getCause());
    assertEquals(error.getErrorType(), errorResult.getErrorType());
    assertEquals(error.getInfo(), errorResult.getInfo());
    assertEquals(error.getTag(), errorResult.getTag());
    assertEquals(error.getSeverity(), errorResult.getSeverity());
    assertEquals(rpc.getResult(), result.get().getResult());
    assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
Also used : GetKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInput) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetKeyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInputBuilder) Test(org.junit.Test)

Example 80 with Error

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error in project genius by opendaylight.

the class ItmManagerRpcService method addL2GwMlagDevice.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> addL2GwMlagDevice(AddL2GwMlagDeviceInput input) {
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    try {
        final IpAddress hwIp = input.getIpAddress();
        final List<String> nodeId = input.getNodeId();
        InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
        Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
        if (transportZonesOptional.isPresent()) {
            TransportZones transportZones = transportZonesOptional.get();
            if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
                LOG.error("No teps configured");
                result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
                return result;
            }
            String transportZone = transportZones.getTransportZone().get(0).getZoneName();
            if (transportZones.getTransportZone().get(0).getSubnets() == null || transportZones.getTransportZone().get(0).getSubnets().isEmpty()) {
                result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
                return result;
            }
            SubnetsKey subnetsKey = transportZones.getTransportZone().get(0).getSubnets().get(0).getKey();
            DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId.get(0));
            InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
            DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(nodeId.get(0)).setTopologyId(input.getTopologyId()).build();
            WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
            // TO DO: add retry if it fails
            LOG.trace("writing hWvtep{}", deviceVtep);
            writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
            if (nodeId.size() == 2) {
                LOG.trace("second node-id {}", nodeId.get(1));
                DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
                InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
                DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().setKey(deviceVtepKey2).setIpAddress(hwIp).setNodeId(nodeId.get(1)).setTopologyId(input.getTopologyId()).build();
                // TO DO: add retry if it fails
                LOG.trace("writing {}", deviceVtep2);
                writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
            }
            ListenableFuture<Void> futureCheck = writeTransaction.submit();
            Futures.addCallback(futureCheck, new FutureCallback<Void>() {

                @Override
                public void onSuccess(Void voidInstance) {
                    result.set(RpcResultBuilder.<Void>success().build());
                }

                @Override
                public void onFailure(Throwable error) {
                    String msg = String.format("Unable to write HwVtep %s to datastore", nodeId);
                    LOG.error("Unable to write HwVtep {}, {} to datastore", nodeId, hwIp);
                    result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
                }
            }, MoreExecutors.directExecutor());
        }
        return result;
    } catch (RuntimeException e) {
        RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
        return Futures.immediateFuture(resultBuilder.build());
    }
}
Also used : DeviceVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DeviceVtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) DeviceVtepsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)81 ArrayList (java.util.ArrayList)65 ExecutionException (java.util.concurrent.ExecutionException)61 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)41 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)30 BigInteger (java.math.BigInteger)29 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)25 List (java.util.List)24 Optional (com.google.common.base.Optional)23 Test (org.junit.Test)22 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)22 RpcError (org.opendaylight.yangtools.yang.common.RpcError)20 Logger (org.slf4j.Logger)20 LoggerFactory (org.slf4j.LoggerFactory)20 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)19 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)17 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)17 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)16 Nonnull (javax.annotation.Nonnull)15 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)15