New Package dealing with device rollback
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / transaction / Connection.java
1 /*
2  * Copyright © 2024 Smartoptics and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer.provisiondevice.transaction;
10
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.transportpce.renderer.provisiondevice.transaction.delete.Delete;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Connection transaction.
19  *
20  * <p>
21  * i.e. a class tracking a connection.
22  */
23 public class Connection implements Transaction {
24
25     private static final Logger LOG = LoggerFactory.getLogger(Connection.class);
26     private final String deviceId;
27     private final String connectionNumber;
28     private final boolean isOtn;
29
30     public Connection(String deviceId, String connectionNumber, boolean isOtn) {
31         this.deviceId = deviceId;
32         this.connectionNumber = connectionNumber;
33         this.isOtn = isOtn;
34     }
35
36     @Override
37     public boolean rollback(Delete delete) {
38         List<String> supportingInterfaces = delete.deleteCrossConnect(deviceId, connectionNumber, isOtn);
39
40         if (supportingInterfaces == null || supportingInterfaces.size() == 0) {
41             return false;
42         }
43
44         LOG.info("Supporting interfaces {} affected by rollback on {} {}",
45                 String.join(", ", supportingInterfaces), deviceId, connectionNumber);
46
47         return true;
48
49     }
50
51     @Override
52     public String description() {
53         return String.format("Connection %s connection number %s isOtn %s", deviceId,
54                 connectionNumber, isOtn);
55     }
56
57     @Override
58     public boolean equals(Object object) {
59         if (this == object) {
60             return true;
61         }
62         if (!(object instanceof Connection)) {
63             return false;
64         }
65         Connection that = (Connection) object;
66         return isOtn == that.isOtn && Objects.equals(deviceId, that.deviceId)
67                 && Objects.equals(connectionNumber, that.connectionNumber);
68     }
69
70     @Override
71     public int hashCode() {
72         return Objects.hash(deviceId, connectionNumber, isOtn);
73     }
74 }