import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.itm.cli.TepCommandHelper;
+import org.opendaylight.genius.itm.cli.TepException;
import org.opendaylight.genius.itm.globals.ITMConstants;
import org.opendaylight.genius.itm.impl.ItmUtils;
import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
*
* @see VtepConfigSchema
*/
+@Singleton
public class VtepConfigSchemaListener extends AbstractDataChangeListener<VtepConfigSchema> implements AutoCloseable {
/** The Constant LOG. */
/**
* Instantiates a new vtep config schema listener.
*
- * @param db
+ * @param dataBroker
* the db
*/
- public VtepConfigSchemaListener(final DataBroker db) {
+ @Inject
+ public VtepConfigSchemaListener(final DataBroker dataBroker) {
super(VtepConfigSchema.class);
- this.dataBroker = db;
- registerListener(db);
+ this.dataBroker = dataBroker;
+ }
+
+ @PostConstruct
+ public void start() throws Exception {
+ registerListener(this.dataBroker);
+ LOG.info("VtepConfigSchemaListener Started");
}
/*
* @see java.lang.AutoCloseable#close()
*/
@Override
+ @PreDestroy
public void close() throws Exception {
if (this.listenerRegistration != null) {
try {
String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
deleteVtepIpPool(subnetCidr);
} catch (Exception e) {
- String error = new StringBuilder("Failed to handle DCN for delete VtepConfigSchema: ").append(schema)
- .toString();
+ String error = "Failed to handle DCN for delete VtepConfigSchema: " + schema;
LOG.error(error, e);
}
}
handleUpdateOfDpnIds(orignalSchema, updatedSchema);
} catch (Exception e) {
- String error = new StringBuilder("Failed to handle DCN for update VtepConfigSchema original:")
- .append(original).append(", updated: ").append(updated).toString();
+ String error = "Failed to handle DCN for update VtepConfigSchema original:" +
+ original + ", updated: " + updated;
LOG.error(error, e);
}
}
*/
private void handleUpdateOfDpnIds(VtepConfigSchema original, VtepConfigSchema updated) {
// Handling add/delete DPNs from schema
- List<DpnIds> originalDpnIds = (original.getDpnIds() == null) ? new ArrayList<DpnIds>()
+ List<DpnIds> originalDpnIds = (original.getDpnIds() == null) ? new ArrayList<>()
: original.getDpnIds();
- List<DpnIds> updatedDpnIds = (updated.getDpnIds() == null) ? new ArrayList<DpnIds>()
+ List<DpnIds> updatedDpnIds = (updated.getDpnIds() == null) ? new ArrayList<>()
: updated.getDpnIds();
handleDeletedDpnsFromSchema(original, originalDpnIds, updatedDpnIds);
* @return the all vtep config schemas
*/
private List<VtepConfigSchema> getAllVtepConfigSchemas() {
- Optional<VtepConfigSchemas> schemas = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
- ItmUtils.getVtepConfigSchemasIdentifier(), this.dataBroker);
- if (schemas.isPresent()) {
- return schemas.get().getVtepConfigSchema();
- }
- return null;
+ return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepConfigSchemasIdentifier(),
+ this.dataBroker).transform(VtepConfigSchemas::getVtepConfigSchema).orNull();
}
/**
skippedDpnIds.add(dpnId);
continue;
}
- tepCommandHelper.createLocalCache(dpnId, schema.getPortName(), schema.getVlanId(),
- String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName());
+ try {
+ tepCommandHelper.createLocalCache(dpnId, schema.getPortName(), schema.getVlanId(),
+ String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
+ } catch (TepException e) {
+ LOG.error(e.getMessage());
+ }
newlyAllocatedIps.add(ipAddress);
}
if (!skippedDpnIds.isEmpty()) {
}
IpAddress ipAddress = vtep.getIpAddress();
- tepCommandHelper.deleteVtep(dpnId, vtep.getPortname(), schema.getVlanId(),
- String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName());
+ try {
+ tepCommandHelper.deleteVtep(dpnId, vtep.getPortname(), schema.getVlanId(),
+ String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
+ } catch (TepException e) {
+ LOG.error(e.getMessage());
+ }
freeIps.add(ipAddress);
}
List<IpAddress> availableIps = calculateAvailableIps(subnetUtils, schema.getExcludeIpFilter(),
schema.getGatewayIp());
VtepIpPool vtepIpPool = new VtepIpPoolBuilder().setSubnetCidr(subnetCidr).setAvailableIpaddress(availableIps)
- .setAllocatedIpaddress(new ArrayList<IpAddress>()).build();
+ .setAllocatedIpaddress(new ArrayList<>()).build();
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION,
ItmUtils.getVtepIpPoolIdentifier(subnetCidr), vtepIpPool);
* @return the vtep ip pool
*/
private VtepIpPool getVtepIpPool(final String subnetCidr) {
- Optional<VtepIpPool> vtepIpPool = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
- ItmUtils.getVtepIpPoolIdentifier(subnetCidr), this.dataBroker);
- if (vtepIpPool.isPresent()) {
- return vtepIpPool.get();
- }
- return null;
+ return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepIpPoolIdentifier(subnetCidr),
+ this.dataBroker).orNull();
}
/**