private ListenableFuture<RpcResult<Void>> chainL3EPServiceIfEpAbsent(final RegisterEndpointInput epInput) { AddressEndpointReg addressEndpoint = epInput.getAddressEndpointReg().get(0); CheckedFuture<Optional<AddressEndpoint>, ReadFailedException> existingEndpointFuture = findExistingEndPoint(addressEndpoint.getContextId(), addressEndpoint.getAddress()); return Futures.transform(existingEndpointFuture, new AsyncFunction<Optional<AddressEndpoint>, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(final Optional<AddressEndpoint> input) throws Exception { final ListenableFuture<RpcResult<Void>> nextResult; if (input == null || !input.isPresent() || !isSameEpg(epInput, input.get())) { // invoke service return JdkFutureAdapters.listenInPoolThread(l3EndpointService.registerEndpoint(epInput)); } else { final String existingL3EpMsg = String.format("address-endpoint for given key already exists: %s | %s", addressEndpoint.getContextId(), addressEndpoint.getAddress() ); nextResult = Futures.immediateFailedFuture(new IllegalStateException(existingL3EpMsg)); } return nextResult; } }); }
private void registerBaseEndpointAndStoreMapping(List<AddressEndpointReg> addrEpRegs, Port port, WriteTransaction wTx) { RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder().setAddressEndpointReg(addrEpRegs) .build(); boolean isRegisteredBaseEndpoint = epRegistrator.registerEndpoint(regBaseEpInput); if (!isRegisteredBaseEndpoint) { LOG.error("Failed to register an address endpoint: {}", addrEpRegs); return; } for (AddressEndpointReg addrEpReg : addrEpRegs) { if (MappingUtils.L2_BRDIGE_DOMAIN.equals(addrEpReg.getContextType())) { UniqueId portId = new UniqueId(port.getUuid().getValue()); LOG.trace("Adding Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid()); AddressEndpointKey addrEpKey = new AddressEndpointKey(addrEpReg.getAddress(), addrEpReg.getAddressType(), addrEpReg.getContextId(), addrEpReg.getContextType()); addBaseEndpointMappings(addrEpKey, portId, wTx); } } }
private boolean isSameEpg(RegisterEndpointInput epInput, AddressEndpoint input) { if (epInput == null || epInput.getAddressEndpointReg() == null || epInput.getAddressEndpointReg().isEmpty()) { return true; } final AddressEndpointReg epInputAddressEndpoint = epInput.getAddressEndpointReg().get(0); if (epInputAddressEndpoint.getEndpointGroup() == null || epInputAddressEndpoint.getEndpointGroup().isEmpty()) { return true; } if (input == null || input.getEndpointGroup() == null || input.getEndpointGroup().isEmpty()) { return true; } final EndpointGroupId addressEndpointGroupId = epInputAddressEndpoint.getEndpointGroup().get(0); final EndpointGroupId existingEndpointGroupId = input.getEndpointGroup().get(0); return addressEndpointGroupId.equals(existingEndpointGroupId); }
@Override public ListenableFuture<RpcResult<Void>> apply(final Optional<AddressEndpoint> input) throws Exception { final ListenableFuture<RpcResult<Void>> nextResult; if (input == null || !input.isPresent() || !isSameEpg(epInput, input.get())) { // invoke service return JdkFutureAdapters.listenInPoolThread(l3EndpointService.registerEndpoint(epInput)); } else { final String existingL3EpMsg = String.format("address-endpoint for given key already exists: %s | %s", addressEndpoint.getContextId(), addressEndpoint.getAddress() ); nextResult = Futures.immediateFailedFuture(new IllegalStateException(existingL3EpMsg)); } return nextResult; } });