From 95b153d2f6c03ca0a16049abac531bac630f0525 Mon Sep 17 00:00:00 2001 From: Evangelos Chaniotakis Date: Tue, 29 Oct 2024 12:56:53 -0700 Subject: [PATCH] fix: [OS-371] Nsi provisioning hotfix (#491) * NSI provisioning fix; remove RANCID * Further provisioning fix * update pom --- CHANGES.md | 6 + backend/config/application.properties | 3 - backend/pom.xml | 2 +- .../net/es/oscars/nsi/beans/NsiModify.java | 3 +- .../es/oscars/nsi/svc/NsiRequestManager.java | 2 +- .../net/es/oscars/nsi/svc/NsiService.java | 49 ++- .../net/es/oscars/nsi/svc/NsiStateEngine.java | 8 +- .../net/es/oscars/sb/SouthboundQueuer.java | 25 +- .../es/oscars/sb/rancid/RancidAdapter.java | 345 ------------------ .../net/es/oscars/sb/rancid/RancidProxy.java | 16 - .../es/oscars/sb/rancid/RestRancidServer.java | 78 ---- .../es/oscars/sb/rancid/StubRancidServer.java | 69 ---- .../java/net/es/oscars/soap/NsiProvider.java | 3 +- 13 files changed, 59 insertions(+), 550 deletions(-) delete mode 100644 backend/src/main/java/net/es/oscars/sb/rancid/RancidAdapter.java delete mode 100644 backend/src/main/java/net/es/oscars/sb/rancid/RancidProxy.java delete mode 100644 backend/src/main/java/net/es/oscars/sb/rancid/RestRancidServer.java delete mode 100644 backend/src/main/java/net/es/oscars/sb/rancid/StubRancidServer.java diff --git a/CHANGES.md b/CHANGES.md index 06c1b223..f5cacefd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,10 @@ # OSCARS Release Notes +### 1.2.15 +> Oct 2024 +- NSI modify hotfix +- remove RANCID code + + ### 1.2.14 > Oct 2024 - NSI modify fix diff --git a/backend/config/application.properties b/backend/config/application.properties index 26b9f336..e9543d60 100644 --- a/backend/config/application.properties +++ b/backend/config/application.properties @@ -77,9 +77,6 @@ pss.config-timeout-sec=180 pss.server-type=stub pss.sync-from-after-legacy-dismantle=false -spring.ssl.bundle.jks.pss.truststore.location=classpath:config/oscars.jks -spring.ssl.bundle.jks.pss.truststore.password=changeit - pce.engine=yenk #pce.engine=allpaths pce.timeout=5 diff --git a/backend/pom.xml b/backend/pom.xml index c553a843..7709f235 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -14,7 +14,7 @@ net.es.oscars backend backend - 1.2.14 + 1.2.15 OSCARS backend diff --git a/backend/src/main/java/net/es/oscars/nsi/beans/NsiModify.java b/backend/src/main/java/net/es/oscars/nsi/beans/NsiModify.java index 0fc779fd..b1cd0553 100644 --- a/backend/src/main/java/net/es/oscars/nsi/beans/NsiModify.java +++ b/backend/src/main/java/net/es/oscars/nsi/beans/NsiModify.java @@ -9,7 +9,7 @@ @Builder public class NsiModify { public String nsiConnectionId; - public Instant revertTime; + public Instant timeout; public Spec initial; private Spec modified; @@ -19,5 +19,6 @@ public static class Spec { Instant beginning; Instant ending; int bandwidth; + int dataplaneVersion; } } diff --git a/backend/src/main/java/net/es/oscars/nsi/svc/NsiRequestManager.java b/backend/src/main/java/net/es/oscars/nsi/svc/NsiRequestManager.java index 2824f367..6a4463e3 100644 --- a/backend/src/main/java/net/es/oscars/nsi/svc/NsiRequestManager.java +++ b/backend/src/main/java/net/es/oscars/nsi/svc/NsiRequestManager.java @@ -30,7 +30,7 @@ public void commit(String nsiConnectionId) { public List timedOut() { List result = new ArrayList<>(); for (NsiModify modify : inFlightModifies.values()) { - if (modify.getRevertTime().isAfter(Instant.now())) { + if (modify.getTimeout().isBefore(Instant.now())) { result.add(modify); } } diff --git a/backend/src/main/java/net/es/oscars/nsi/svc/NsiService.java b/backend/src/main/java/net/es/oscars/nsi/svc/NsiService.java index 7891c187..fe5e669a 100644 --- a/backend/src/main/java/net/es/oscars/nsi/svc/NsiService.java +++ b/backend/src/main/java/net/es/oscars/nsi/svc/NsiService.java @@ -185,7 +185,8 @@ public void reserve(CommonHeaderType header, ReserveType rt, NsiMapping mapping) log.info("ending reserve"); }); } - public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping) { + + public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping, int newVersion) { Executors.newCachedThreadPool().submit(() -> { log.info("starting modify task"); DevelUtils.dumpDebug("modifyRT", rt); @@ -197,6 +198,7 @@ public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping) Instant initialBeginning = c.getReserved().getSchedule().getBeginning(); Instant initialEnding = c.getReserved().getSchedule().getEnding(); + int initialDataplaneVersion = mapping.getDataplaneVersion(); int initialBandwidth = 0; for (VlanFixture f : c.getReserved().getCmp().getFixtures()) { @@ -235,8 +237,8 @@ public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping) newEnding = xet.toGregorianCalendar().toInstant(); } - // we increment the dataplane version - mapping.setDataplaneVersion(mapping.getDataplaneVersion() + 1); + // we update the dataplane version + mapping.setDataplaneVersion(newVersion); nsiRepo.save(mapping); Validity v = connSvc.modifyNsi(c, newBandwidth, newBeginning, newEnding); @@ -268,13 +270,15 @@ public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping) .bandwidth(initialBandwidth) .beginning(initialBeginning) .ending(initialEnding) + .dataplaneVersion(initialDataplaneVersion) .build()) .modified(NsiModify.Spec.builder() .bandwidth(newBandwidth) .beginning(newBeginning) .ending(newEnding) + .dataplaneVersion(newVersion) .build()) - .revertTime(timeout) + .timeout(timeout) .nsiConnectionId(mapping.getNsiConnectionId()) .build(); @@ -319,14 +323,17 @@ public void modify(CommonHeaderType header, ReserveType rt, NsiMapping mapping) public void commit(CommonHeaderType header, NsiMapping mapping) { Executors.newCachedThreadPool().submit(() -> { - log.info("starting commit task"); + log.info("starting commit for "+mapping.getNsiConnectionId()); try { nsiStateEngine.commit(NsiEvent.COMMIT_START, mapping); Connection c = nsiConnectionAccess.getOscarsConnection(mapping); // The commit could be either a commit for the initial commit flow or it can // be for an in-flight modify. + + // if (nsiRequestManager.getInFlightModify(mapping.getNsiConnectionId()) == null) { + log.info("commit for initial reserve"); if (!c.getPhase().equals(Phase.HELD)) { throw new NsiException("Invalid connection phase", NsiErrors.TRANS_ERROR); } @@ -334,6 +341,13 @@ public void commit(CommonHeaderType header, NsiMapping mapping) { } else { // tell the request manager that this committed OK + log.info("committing modify " + mapping.getNsiConnectionId()); + + NsiModify modify = nsiRequestManager.getInFlightModify(mapping.getNsiConnectionId()); + mapping.setDataplaneVersion(modify.getModified().getDataplaneVersion()); + nsiRepo.save(mapping); + log.info("new dataplane version " + mapping.getDataplaneVersion()); + nsiRequestManager.commit(mapping.getNsiConnectionId()); } @@ -346,7 +360,7 @@ public void commit(CommonHeaderType header, NsiMapping mapping) { } catch (WebServiceException | ServiceException ex) { log.error("commit confirmed callback failed", ex); } - } catch ( PCEException | NsiException ex) { + } catch (PCEException | NsiException ex) { log.error("failed commit"); log.error(ex.getMessage(), ex); try { @@ -509,7 +523,22 @@ public void terminate(CommonHeaderType header, NsiMapping mapping) { public void rollbackModify(NsiMapping mapping) { log.info("modify timed out for " + mapping.getNsiConnectionId() + " " + mapping.getOscarsConnectionId()); - this.resvTimedOut(mapping); + NsiModify modify = nsiRequestManager.getInFlightModify(mapping.getNsiConnectionId()); + + Connection c = connSvc.findConnection(mapping.getOscarsConnectionId()); + + + try { + log.info("rolling back modify " + mapping.getNsiConnectionId() + " " + mapping.getOscarsConnectionId()); + connSvc.modifyNsi(c, modify.getInitial().getBandwidth(), modify.getInitial().getBeginning(), modify.getInitial().getEnding()); + } catch (ModifyException ex) { + log.error("Internal error: " + ex.getMessage(), ex); + } finally { + mapping.setDataplaneVersion(modify.getInitial().getDataplaneVersion()); + nsiRepo.save(mapping); + this.resvTimedOut(mapping); + } + } // currently unused @@ -947,7 +976,7 @@ public List pipesFor(Interval interval, Integer mbps, include.add(0, junctions.get(0).getDevice()); } // last element of ero should be the last device. - if (!include.get(include.size()-1).equals(junctions.get(1).getDevice())) { + if (!include.get(include.size() - 1).equals(junctions.get(1).getDevice())) { include.add(junctions.get(1).getDevice()); } @@ -1542,12 +1571,13 @@ public ScheduleType oscarsToNsiSchedule(Schedule sch) throws NsiException { return st; } + public Long getModifyCapacity(ReserveType rt) throws NsiException { ReservationRequestCriteriaType crit = rt.getCriteria(); Long result = null; for (Object obj : crit.getAny()) { if (result == null) { - if (obj instanceof @SuppressWarnings("rawtypes") JAXBElement jaxb) { + if (obj instanceof @SuppressWarnings("rawtypes")JAXBElement jaxb) { if (jaxb.getDeclaredType() == Long.class) { result = ((Long) jaxb.getValue()); if (jaxb.getName().toString().equals("{http://schemas.ogf.org/nsi/2013/12/services/point2point}capacity")) { @@ -1595,7 +1625,6 @@ public P2PServiceBaseType getP2PService(ReserveType rt) throws NsiException { /* db funcs */ - public NsiMapping getMapping(String nsiConnectionId) throws NsiException { if (nsiConnectionId == null || nsiConnectionId.isEmpty()) { throw new NsiException("null or blank connection id! " + nsiConnectionId, NsiErrors.MISSING_PARAM_ERROR); diff --git a/backend/src/main/java/net/es/oscars/nsi/svc/NsiStateEngine.java b/backend/src/main/java/net/es/oscars/nsi/svc/NsiStateEngine.java index 3ec039ff..38d71a96 100644 --- a/backend/src/main/java/net/es/oscars/nsi/svc/NsiStateEngine.java +++ b/backend/src/main/java/net/es/oscars/nsi/svc/NsiStateEngine.java @@ -95,8 +95,14 @@ public void reserve(NsiEvent event, NsiMapping mapping) throws NsiException { public void provision(NsiEvent event, NsiMapping mapping) throws NsiException { + // allowed transitions + // null state -> provisioning via PROV_START + // provisioned -> provisioning via PROV_START + + // provisioning -> provisioned via PROV_CF + if (event.equals(NsiEvent.PROV_START)) { - if (!mapping.getProvisionState().equals(ProvisionStateEnumType.RELEASED)) { + if (!mapping.getProvisionState().equals(ProvisionStateEnumType.RELEASED) && !mapping.getProvisionState().equals(ProvisionStateEnumType.PROVISIONED)) { throw new NsiException("Invalid prov state " + mapping.getProvisionState(), NsiErrors.TRANS_ERROR); } mapping.setProvisionState(ProvisionStateEnumType.PROVISIONING); diff --git a/backend/src/main/java/net/es/oscars/sb/SouthboundQueuer.java b/backend/src/main/java/net/es/oscars/sb/SouthboundQueuer.java index c53f5f54..de34bc63 100644 --- a/backend/src/main/java/net/es/oscars/sb/SouthboundQueuer.java +++ b/backend/src/main/java/net/es/oscars/sb/SouthboundQueuer.java @@ -9,7 +9,6 @@ import net.es.oscars.sb.ent.RouterCommands; import net.es.oscars.sb.nso.NsoAdapter; import net.es.oscars.sb.beans.QueueName; -import net.es.oscars.sb.rancid.RancidAdapter; import net.es.oscars.resv.db.ConnectionRepository; import net.es.oscars.resv.ent.Connection; import net.es.oscars.resv.enums.DeploymentState; @@ -29,8 +28,6 @@ public class SouthboundQueuer { @Autowired private NsoAdapter nsoAdapter; - @Autowired - private RancidAdapter rancidAdapter; @Autowired private ConnectionRepository cr; @@ -78,16 +75,7 @@ public void process() { cr.save(conn); log.info(wt.getConnectionId() + " " + wt.getCommandType() + " dst: " + conn.getDeploymentState()); - - if (isLegacy(conn)) { - if (wt.getCommandType().equals(CommandType.DISMANTLE)) { - this.completeTask(rancidAdapter.processTask(conn, wt.getCommandType(), wt.getIntent())); - } else { - log.warn("not performing non-dismantle task for legacy connection " + conn.getConnectionId()); - } - } else { - this.completeTask(nsoAdapter.processTask(conn, wt.getCommandType(), wt.getIntent())); - } + this.completeTask(nsoAdapter.processTask(conn, wt.getCommandType(), wt.getIntent())); }); } waiting.clear(); @@ -127,17 +115,6 @@ public void completeTask(SouthboundTaskResult result) { } } - // a connection is legacy if it has any old-style dismantle commands - public boolean isLegacy(Connection conn) { - for (VlanJunction j : conn.getArchived().getCmp().getJunctions()) { - RouterCommands existing = rancidAdapter.existing(conn.getConnectionId(), j.getDeviceUrn(), CommandType.DISMANTLE); - if (existing != null) { - return !existing.getTemplateVersion().equals("NSO 1.1"); - } - } - return false; - } - public void clear(QueueName name) { switch (name) { case DONE -> this.done.clear(); diff --git a/backend/src/main/java/net/es/oscars/sb/rancid/RancidAdapter.java b/backend/src/main/java/net/es/oscars/sb/rancid/RancidAdapter.java deleted file mode 100644 index fde1e995..00000000 --- a/backend/src/main/java/net/es/oscars/sb/rancid/RancidAdapter.java +++ /dev/null @@ -1,345 +0,0 @@ -package net.es.oscars.sb.rancid; - -import lombok.extern.slf4j.Slf4j; -import net.es.oscars.app.exc.NotReadyException; -import net.es.oscars.app.exc.PSSException; -import net.es.oscars.app.props.PssProperties; -import net.es.oscars.app.syslog.Syslogger; -import net.es.oscars.dto.pss.cmd.Command; -import net.es.oscars.dto.pss.cmd.CommandResponse; -import net.es.oscars.dto.pss.cmd.CommandStatus; -import net.es.oscars.dto.pss.cmd.CommandType; -import net.es.oscars.dto.pss.st.ConfigStatus; -import net.es.oscars.dto.pss.st.LifecycleStatus; - -import net.es.oscars.sb.db.RouterCommandsRepository; -import net.es.oscars.sb.ent.RouterCommandHistory; -import net.es.oscars.sb.ent.RouterCommands; -import net.es.oscars.resv.db.CommandHistoryRepository; -import net.es.oscars.resv.ent.Connection; -import net.es.oscars.resv.ent.Event; -import net.es.oscars.resv.ent.VlanJunction; -import net.es.oscars.resv.enums.DeploymentState; -import net.es.oscars.resv.enums.EventType; -import net.es.oscars.resv.enums.State; -import net.es.oscars.resv.svc.LogService; -import net.es.oscars.sb.SouthboundTaskResult; -import net.es.oscars.sb.nso.NsoProxy; -import net.es.oscars.topo.beans.TopoUrn; -import net.es.oscars.topo.enums.UrnType; -import net.es.oscars.topo.svc.TopologyStore; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; -import java.util.stream.Collectors; - -@Component -@Slf4j -public class RancidAdapter { - private RancidProxy rancidProxy; - - - private NsoProxy nsoProxy; - - private PssProperties properties; - private RouterCommandsRepository rcr; - private CommandHistoryRepository historyRepo; - private LogService logService; - private TopologyStore topologyStore; - private Syslogger syslogger; - - @Autowired - public RancidAdapter(RancidProxy rancidProxy, RouterCommandsRepository rcr, CommandHistoryRepository historyRepo, Syslogger syslogger, - TopologyStore topologyStore, LogService logService, NsoProxy nsoProxy, PssProperties properties) { - this.rancidProxy = rancidProxy; - this.rcr = rcr; - this.historyRepo = historyRepo; - this.topologyStore = topologyStore; - this.logService = logService; - this.nsoProxy = nsoProxy; - this.properties = properties; - this.syslogger = syslogger; - } - - public SouthboundTaskResult processTask(Connection conn, CommandType commandType, State intent) { - log.info("processing southbound PSS task "+conn.getConnectionId()+" "+commandType.toString()); - State newState; - DeploymentState incomingDepState = DeploymentState.DEPLOYED; - DeploymentState newDepState; - - - try { - State dismantleResult = this.dismantle(conn); - if (dismantleResult.equals(State.FAILED)) { - newDepState = incomingDepState; - newState = State.FAILED; - } else { - newDepState = DeploymentState.UNDEPLOYED; - newState = intent; - } - } catch (PSSException | NotReadyException e) { - newDepState = incomingDepState; - newState = State.FAILED; - } - - log.info("processed "+conn.getConnectionId()+" "+commandType); - return SouthboundTaskResult.builder() - .commandType(commandType) - .connectionId(conn.getConnectionId()) - .deploymentState(newDepState) - .state(newState) - .build(); - } - - - public State dismantle(Connection conn) throws PSSException, NotReadyException { - log.info("dismantling " + conn.getConnectionId()); - List commands = this.configCommands(conn, CommandType.DISMANTLE); - - List devices = new ArrayList<>(); - for (Command c: commands) { - devices.add(c.getDevice()); - } - String dStr = String.join(", ", devices); - syslogger.sendSyslog( "OSCARS DISMANTLE STARTED : " + conn.getConnectionId()+ " : ( "+dStr+" ) : '"+ conn.getDescription()+"'"); - - List stable = this.getStableStatuses(commands); - Instant now = Instant.now(); - State result = State.WAITING; - for (CommandStatus st : stable) { - RouterCommands rc = this.existing(conn.getConnectionId(), st.getDevice(), CommandType.DISMANTLE); - - RouterCommandHistory rch = RouterCommandHistory.builder() - .connectionId(conn.getConnectionId()) - .date(now) - .deviceUrn(st.getDevice()) - .commands(st.getCommands()) - .templateVersion(rc.getTemplateVersion()) - .output(st.getOutput()) - .configStatus(st.getConfigStatus()) - .type(CommandType.DISMANTLE) - .build(); - - historyRepo.save(rch); - if (st.getConfigStatus().equals(ConfigStatus.ERROR)) { - result = State.FAILED; - Event ev = Event.builder() - .connectionId(conn.getConnectionId()) - .description("PSS dismantle failed") - .type(EventType.ERROR) - .occurrence(Instant.now()) - .username("system") - .build(); - logService.logEvent(conn.getConnectionId(), ev); - syslogger.sendSyslog( "OSCARS DISMANTLE FAILED : " + conn.getConnectionId()); - } else { - Event ev = Event.builder() - .connectionId(conn.getConnectionId()) - .description("dismantled successfully") - .type(EventType.DISMANTLED) - .occurrence(Instant.now()) - .username("system") - .build(); - logService.logEvent(conn.getConnectionId(), ev); - - // Send Syslog Message - syslogger.sendSyslog( "OSCARS DISMANTLE COMPLETED : " + conn.getConnectionId()); - } - } - - if (properties.getSyncFromAfterLegacyDismantle()) { - for (String device : devices) { - log.info("performing post-dismantle sync-from on "+device); - nsoProxy.syncFrom(device); - } - } - - return result; - } - - - public List getStableStatuses(List commands) throws PSSException { - try { - List responses = parallelSubmit(commands); - List commandIds = responses.stream() - .map(CommandResponse::getCommandId) - .collect(Collectors.toList()); - return pollUntilStable(commandIds); - - } catch (InterruptedException | ExecutionException ex) { - throw new PSSException("interrupted"); - } - } - - public List pollUntilStable(List commandIds) - throws PSSException { - - boolean allDone = false; - boolean timedOut = false; - int timeoutMillis = properties.getConfigTimeoutSec() * 1000; - int elapsed = 0; - List statuses = new ArrayList<>(); - - try { - while (!allDone && !timedOut) { - log.info("polling PSS.. "); - statuses = pollStatuses(commandIds); - allDone = areAllDone(statuses); - - if (!allDone) { - Thread.sleep(1000); - elapsed = elapsed + 1000; - if (elapsed > timeoutMillis) { - timedOut = true; - log.error("timed out!"); - } - } - } - } catch (InterruptedException | ExecutionException ex) { - log.error("interrupted!", ex); - throw new PSSException("PSS thread interrupted"); - } - - if (timedOut) { - throw new PSSException("timed out waiting for all routers to be stable"); - } - - return statuses; - } - - private boolean areAllDone(List statuses) { - boolean allDone = true; - for (CommandStatus st : statuses) { - if (!st.getLifecycleStatus().equals(LifecycleStatus.DONE)) { - allDone = false; - break; - } - } - return allDone; - } - - public List parallelSubmit(List commands) - throws InterruptedException, ExecutionException { - List responses = new ArrayList<>(); - - int threadNum = commands.size(); - if (threadNum == 0) { - return responses; - } - ExecutorService executor = Executors.newFixedThreadPool(threadNum); - - List> taskList = new ArrayList<>(); - for (Command cmd : commands) { - log.info("submit to PSS: "+cmd.getConnectionId()); - FutureTask task = new FutureTask<>(() -> rancidProxy.submitCommand(cmd)); - taskList.add(task); - executor.execute(task); - } - for (int j = 0; j < threadNum; j++) { - FutureTask futureTask = taskList.get(j); - responses.add(taskList.get(j).get()); - log.info("got response " + futureTask.get().getCommandId()); - } - executor.shutdown(); - return responses; - } - - public List pollStatuses(List commandIds) - throws InterruptedException, ExecutionException { - List statuses = new ArrayList<>(); - int threadNum = commandIds.size(); - if (threadNum == 0) { - return statuses; - } - ExecutorService executor = Executors.newFixedThreadPool(threadNum); - - List> taskList = new ArrayList<>(); - for (String commandId : commandIds) { - FutureTask task = new FutureTask<>(() -> rancidProxy.status(commandId)); - taskList.add(task); - executor.execute(task); - } - - for (int j = 0; j < threadNum; j++) { - statuses.add(taskList.get(j).get()); - } - executor.shutdown(); - return statuses; - } - - public List configCommands(Connection conn, CommandType ct) throws PSSException, NotReadyException { - log.info("gathering "+ct+" commands for " + conn.getConnectionId()); - List commands = new ArrayList<>(); - - boolean hadError = false; - - for (VlanJunction j : conn.getArchived().getCmp().getJunctions()) { - RouterCommands existing = existing(conn.getConnectionId(), j.getDeviceUrn(), ct); - if (existing != null) { - Command cmd = this.makeCmd(conn.getConnectionId(), ct, j.getDeviceUrn()); - commands.add(cmd); - - } else { - log.error(ct+" config does not exist for " + conn.getConnectionId()); - hadError = true; - } - } - int needed = conn.getArchived().getCmp().getJunctions().size(); - int got = commands.size(); - - log.info("gathered " + got + "/"+needed+" commands"); - if (hadError) { - throw new NotReadyException("waiting for all "+needed+" commands to be generated for "+conn.getConnectionId()); - } - - return commands; - } - - public RouterCommands existing(String connId, String deviceUrn, CommandType commandType) { - List existing = rcr.findByConnectionIdAndDeviceUrn(connId, deviceUrn); - for (RouterCommands rc : existing) { - if (rc.getType().equals(commandType)) { - return rc; - } - } - return null; - } - - public List opCheckCommands(Connection conn) throws PSSException { - log.info("gathering op check commands for " + conn.getConnectionId()); - List commands = new ArrayList<>(); - - for (VlanJunction j : conn.getArchived().getCmp().getJunctions()) { - Command cmd = this.makeCmd(conn.getConnectionId(), CommandType.OPERATIONAL_STATUS, j.getDeviceUrn()); - commands.add(cmd); - } - - log.info("gathered " + commands.size() + " commands"); - - - return commands; - } - - private Command makeCmd(String connId, CommandType type, String device) throws PSSException { - TopoUrn devUrn = topologyStore.getTopoUrnMap().get(device); - if (devUrn == null) { - throw new PSSException("could not locate topo URN for "+device); - - } - if (!devUrn.getUrnType().equals(UrnType.DEVICE)) { - throw new PSSException("bad urn type"); - } - - return Command.builder() - .connectionId(connId) - .type(type) - .model(devUrn.getDevice().getModel()) - .device(devUrn.getUrn()) - .profile(properties.getProfile()) - .build(); - } -} \ No newline at end of file diff --git a/backend/src/main/java/net/es/oscars/sb/rancid/RancidProxy.java b/backend/src/main/java/net/es/oscars/sb/rancid/RancidProxy.java deleted file mode 100644 index fb40eb15..00000000 --- a/backend/src/main/java/net/es/oscars/sb/rancid/RancidProxy.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.es.oscars.sb.rancid; - - -import com.google.common.base.VerifyException; -import net.es.oscars.app.exc.PSSException; -import net.es.oscars.dto.pss.cmd.*; - -public interface RancidProxy { - - CommandResponse submitCommand(Command cmd) throws PSSException; - - CommandStatus status(String commandId) throws PSSException; - - DeviceConfigResponse getConfig(DeviceConfigRequest request) throws VerifyException; - -} \ No newline at end of file diff --git a/backend/src/main/java/net/es/oscars/sb/rancid/RestRancidServer.java b/backend/src/main/java/net/es/oscars/sb/rancid/RestRancidServer.java deleted file mode 100644 index b1e2e899..00000000 --- a/backend/src/main/java/net/es/oscars/sb/rancid/RestRancidServer.java +++ /dev/null @@ -1,78 +0,0 @@ -package net.es.oscars.sb.rancid; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry; -import lombok.extern.slf4j.Slf4j; -import net.es.oscars.app.props.PssProperties; -import net.es.oscars.dto.pss.cmd.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.ssl.SslBundles; -import org.springframework.boot.web.client.RestTemplateBuilder; - -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -@Component -@Slf4j -@ConditionalOnProperty(name="pss.server-type", havingValue = "rest") -public class RestRancidServer implements RancidProxy { - private final PssProperties props; - private RestTemplate restTemplate; - - final OpenTelemetry openTelemetry; - - @Autowired - public RestRancidServer(PssProperties props, RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles, OpenTelemetry openTelemetry) { - - this.props = props; - this.openTelemetry = openTelemetry; - SpringWebTelemetry telemetry = SpringWebTelemetry.create(openTelemetry); - - try { - this.restTemplate = restTemplateBuilder - .setSslBundle(sslBundles.getBundle("pss")) - .basicAuthentication(props.getUsername(), props.getPassword()) - .build(); - this.restTemplate.getInterceptors().add(telemetry.newInterceptor()); - - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - log.info("PSS server URL: " + props.getUrl()); - } - - - public CommandResponse submitCommand(Command cmd) { - if (cmd.getType().equals(CommandType.CONTROL_PLANE_STATUS)) { - log.info("submit command - device " + cmd.getDevice()); - - } else { - log.info("submit command - conn id: " + cmd.getConnectionId() + " , dev: " + cmd.getDevice()); - - } - String pssUrl = props.getUrl(); - String submitUrl = "/command"; - String restPath = pssUrl + submitUrl; - return restTemplate.postForObject(restPath, cmd, CommandResponse.class); - - } - - public DeviceConfigResponse getConfig(DeviceConfigRequest request) { - log.info("getConfig - device " + request.getDevice()); - String pssUrl = props.getUrl(); - String submitUrl = "/getConfig"; - String restPath = pssUrl + submitUrl; - return restTemplate.postForObject(restPath, request, DeviceConfigResponse.class); - } - - - public CommandStatus status(String commandId) { - log.info("status - cmd id " + commandId); - String pssUrl = props.getUrl(); - String submitUrl = "/status/" + commandId; - String restPath = pssUrl + submitUrl; - return restTemplate.getForObject(restPath, CommandStatus.class); - } - -} \ No newline at end of file diff --git a/backend/src/main/java/net/es/oscars/sb/rancid/StubRancidServer.java b/backend/src/main/java/net/es/oscars/sb/rancid/StubRancidServer.java deleted file mode 100644 index 77c35322..00000000 --- a/backend/src/main/java/net/es/oscars/sb/rancid/StubRancidServer.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.es.oscars.sb.rancid; - -import lombok.extern.slf4j.Slf4j; -import net.es.oscars.dto.pss.cmd.*; -import net.es.oscars.dto.pss.st.ConfigStatus; -import net.es.oscars.dto.pss.st.LifecycleStatus; -import net.es.oscars.dto.pss.st.OperationalStatus; -import net.es.oscars.sb.db.RouterCommandsRepository; -import net.es.oscars.sb.ent.RouterCommands; -import org.hashids.Hashids; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - - -@Component -@Slf4j -@ConditionalOnProperty(name="pss.server-type", havingValue = "stub") -public class StubRancidServer implements RancidProxy { - private Map statusMap = new HashMap<>(); - private Hashids hashids = new Hashids("ESnet salt"); - - @Autowired - private RouterCommandsRepository rcRepo; - - public CommandResponse submitCommand(Command cmd) { - Integer id = new Random().nextInt(0, 1000000); - - String commandsString = ""; - for (RouterCommands rc : rcRepo.findByConnectionIdAndDeviceUrn(cmd.getConnectionId(), cmd.getDevice())) { - if (rc.getType().equals(cmd.getType())) { - commandsString = rc.getContents(); - } - } - - String commandId = hashids.encode(id); - CommandStatus cs = CommandStatus.builder() - .type(cmd.getType()) - .device(cmd.getDevice()) - .profile(cmd.getProfile()) - .connectionId(cmd.getConnectionId()) - .output("stub output - commands were: \n"+commandsString) - .commands(commandsString) - .configStatus(ConfigStatus.OK) - .lifecycleStatus(LifecycleStatus.DONE) - .operationalStatus(OperationalStatus.OK) - .build(); - statusMap.put(commandId, cs); - return CommandResponse.builder() - .commandId(commandId) - .device(cmd.getDevice()) - .connectionId(cmd.getConnectionId()) - .build(); - } - - public DeviceConfigResponse getConfig(DeviceConfigRequest request) { - return DeviceConfigResponse.builder().build(); - } - - - public CommandStatus status(String commandId) { - return this.statusMap.get(commandId); - } - -} \ No newline at end of file diff --git a/backend/src/main/java/net/es/oscars/soap/NsiProvider.java b/backend/src/main/java/net/es/oscars/soap/NsiProvider.java index 01597fcc..bb631551 100644 --- a/backend/src/main/java/net/es/oscars/soap/NsiProvider.java +++ b/backend/src/main/java/net/es/oscars/soap/NsiProvider.java @@ -95,7 +95,8 @@ public ReserveResponseType reserve(ReserveType reserve, Holder if (stateEngine.findMapping(reserve.getConnectionId()).isPresent()) { mapping = stateEngine.findMapping(reserve.getConnectionId()).get(); log.info("triggering a modify"); - nsiService.modify(header.value, reserve, mapping); + // pass in the new version + nsiService.modify(header.value, reserve, mapping, reserve.getCriteria().getVersion()); } else { mapping = stateEngine.newMapping( reserve.getConnectionId(),