Revision: 16069
Author: [email protected]
Date: Mon Dec 27 09:28:32 2010
Log: added delete link/linkset abstract api's
http://code.google.com/p/mobicents/source/detail?r=16069
Modified:
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/Linkset.java
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactory.java
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactoryFactory.java
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
Mon Dec 27 04:21:44 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
Mon Dec 27 09:28:32 2010
@@ -5,6 +5,8 @@
/**
* Pre defined messages
*/
+ public static final String INVALID_COMMAND = "Invalid Command";
+
public static final String LINKSET_ALREADY_EXIST = "LinkSet already
exist";
public static final String LINKSET_DOESNT_EXIST = "LinkSet doesn't
exist";
@@ -13,55 +15,31 @@
public static final String NOSHUTDOWN_LINKSET_FAILED = "noshutdown for
Linkset failed";
- public static final byte[] NOSHUTDOWN_LINK_SUCCESSFULLY = "noshutdown
for Link successfull"
- .getBytes();
-
- public static final byte[] NOSHUTDOWN_LINK_FAILED = "noshutdown for
Link failed"
- .getBytes();
-
- public static final byte[] NETWORK_INDICATOR_SUCCESSFULLY_SET
= "Network Indicator successfully set"
- .getBytes();
-
- public static final byte[] OPC_SUCCESSFULLY_SET = "Originating Point
Code successfully set"
- .getBytes();
-
- public static final byte[] APC_SUCCESSFULLY_SET = "Adjacent Point Code
successfully set"
- .getBytes();
-
- public static final byte[] LOCAL_IP_PORT_SUCCESSFULLY_SET = "Local
ip:port successfully set"
- .getBytes();
-
- public static final byte[] LINK_DOESNT_EXIST = "Link doesn't exist"
- .getBytes();
+ public static final String NOSHUTDOWN_LINK_SUCCESSFULLY = "noshutdown
for Link successfull";
+
+ public static final String NOSHUTDOWN_LINK_FAILED = "noshutdown for
Link failed";
+
+ public static final String LINK_DOESNT_EXIST = "Link doesn't exist";
public static final String LINKSET_SUCCESSFULLY_ADDED = "LinkSet
successfully added";
- public static final byte[] INCORRECT_LINKSET_TYPE = "LinkSet type is
incorrect"
- .getBytes();
-
- public static final byte[] LINKSET_ALREADY_ACTIVE = "Linkset already
active"
- .getBytes();
-
- public static final byte[] LINKSET_NO_LINKS_CONFIGURED = "No Links for
this LinkSet are configured"
- .getBytes();
-
- public static final byte[] LINK_SUCCESSFULLY_ADDED = "Link
successfully added"
- .getBytes();
-
- public static final byte[] LINK_SPAN_SUCCESSFULL = "Span successfully
set for Link"
- .getBytes();
-
- public static final byte[] LINK_CHANNEL_SUCCESSFULL = "Channel
successfully set for Link"
- .getBytes();
-
- public static final byte[] LINK_CODE_SUCCESSFULL = "Code successfully
set for Link"
- .getBytes();
-
- public static final byte[] LINK_ADD_FAILED = "Addition of Link failed"
- .getBytes();
-
- public static final byte[] LINK_ALREADY_EXIST = "Link already exist"
- .getBytes();
+ public static final String LINKSET_SUCCESSFULLY_REMOVED = "LinkSet
successfully removed";
+
+ public static final String INCORRECT_LINKSET_TYPE = "LinkSet type is
incorrect";
+
+ public static final String LINKSET_ALREADY_ACTIVE = "Linkset already
active";
+
+ public static final String LINKSET_NO_LINKS_CONFIGURED = "No Links for
this LinkSet are configured";
+
+ public static final String LINK_SUCCESSFULLY_ADDED = "Link
successfully added";
+
+ public static final String LINK_SUCCESSFULLY_REMOVED = "Link
successfully removed";
+
+ public static final String CANT_DELETE_LINKSET = "Linkset is
Available. Can't delete. Please Shutdown all links within Linkset and
removed each of them before removing this linkset";
+
+ public static final String LINK_ADD_FAILED = "Addition of Link failed";
+
+ public static final String LINK_ALREADY_EXIST = "Link already exist";
public static final byte[] LINKSET_NOT_DAHDI = "Linkset is of not
Dahdi type"
.getBytes();
@@ -70,7 +48,8 @@
public static final byte[] LINKSET_NOT_M3UA = "Linkset is of not M3UA
type"
.getBytes();
- public static final byte[] NOT_IMPLEMENTED = "Not implemented yet"
- .getBytes();
+ public static final String NOT_IMPLEMENTED = "Not implemented yet";
+
+ public static final String CANT_DELETE_LINK = "Link is Active. Can't
delete. Please Shutdown first";
}
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/Linkset.java
Mon Dec 27 04:21:44 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/Linkset.java
Mon Dec 27 09:28:32 2010
@@ -113,7 +113,9 @@
/**
* Operations
*/
- public abstract boolean addLink(String linkName, ByteBuffer
byteBuffer);
+ public abstract void createLink(String[] options) throws Exception;
+
+ public abstract void deleteLink(String linkName) throws Exception;
public Link getLink(String linkName) {
return this.links.get(linkName);
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactory.java
Mon Dec 27 04:21:44 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactory.java
Mon Dec 27 09:28:32 2010
@@ -11,7 +11,7 @@
public LinksetFactory() {
}
- public abstract Linkset createLinkset(String[] options);
+ public abstract Linkset createLinkset(String[] options) throws
Exception;
public abstract String getName();
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactoryFactory.java
Mon Dec 27 04:21:44 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetFactoryFactory.java
Mon Dec 27 09:28:32 2010
@@ -14,30 +14,28 @@
linksetFactories.remove(factory);
}
- public Linkset createLinkset(String[] options) {
+ public Linkset createLinkset(String[] options) throws Exception {
if (options == null) {
- return null;
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
}
- String firstOption = null;
- int i = 0;
-
- while (i < options.length && (firstOption = options[i]) == null) {
- i++;
+ // The expected command is "linkset create <likset-type> <options>"
+ // Expect atleast length to 3
+ if (options.length < 3) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
}
- if (firstOption == null) {
- return null;
+ String type = options[2];
+
+ if (type == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
}
- LinksetFactory linksetFactory = linksetFactories.get(firstOption);
+ LinksetFactory linksetFactory = linksetFactories.get(type);
if (linksetFactory == null) {
- return null;
- }
-
- options[i] = null;
-
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
return linksetFactory.createLinkset(options);
}
}
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
Mon Dec 27 04:21:44 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
Mon Dec 27 09:28:32 2010
@@ -14,7 +14,6 @@
import org.apache.log4j.Logger;
-
/**
*
* @author amit bhayani
@@ -104,15 +103,25 @@
/**
* Operations
*/
- public String createLinkset(String[] options) {
-
- Linkset linkset =
this.linksetFactoryFactory.createLinkset(options);
+
+ /**
+ * Expected command is "linkset create <linkset-type> <options>
+ * <linkset-name>"
+ *
+ * @param options
+ * @return
+ */
+ public String createLinkset(String[] options) throws Exception {
+
+ Linkset linkset = null;
+
+ linkset = this.linksetFactoryFactory.createLinkset(options);
if (linkset == null) {
return "Invalid Command";
}
- // huh, we parse first and then check for name :(
+ // TODO huh, we parse first and then check for name :(
if (this.linksets.containsKey(linkset.getLinksetName())) {
return LinkOAMMessages.LINKSET_ALREADY_EXIST;
}
@@ -122,6 +131,103 @@
return LinkOAMMessages.LINKSET_SUCCESSFULLY_ADDED;
}
+
+ /**
+ * Expected command is "linkset delete <linkset-name>"
+ *
+ * @param options
+ * @return
+ * @throws Exception
+ */
+ public String deleteLinkset(String[] options) throws Exception {
+ String linksetName = options[(options.length - 1)];
+
+ if (linksetName == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
+ Linkset linkset = this.linksets.get(linksetName);
+
+ if (linkset == null) {
+ throw new Exception(LinkOAMMessages.LINKSET_DOESNT_EXIST);
+ }
+
+ if (linkset.getState() == LinksetState.AVAILABLE) {
+ throw new Exception(LinkOAMMessages.CANT_DELETE_LINKSET);
+ }
+
+ this.linksets.remove(linksetName);
+
+ this.store();
+
+ return LinkOAMMessages.LINKSET_SUCCESSFULLY_REMOVED;
+ }
+
+ /**
+ * Create new Link. The expected command is "linkset link create
<options>
+ * linkset1 link1" where linkset1 is the linkset name and "link1" is
link
+ * name to be created and associated with "linkset1". The <options>
depends
+ * on type of link to be created
+ *
+ * @param options
+ * @return
+ */
+ public String createLink(String[] options) throws Exception {
+
+ if (options == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
+
+ // The second last option is Linkset name
+ String linksetName = options[(options.length - 2)];
+
+ if (linksetName == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
+ Linkset linkset = this.linksets.get(linksetName);
+
+ if (linkset == null) {
+ throw new Exception(LinkOAMMessages.LINKSET_DOESNT_EXIST);
+ }
+
+ linkset.createLink(options);
+
+ this.store();
+
+ return LinkOAMMessages.LINK_SUCCESSFULLY_ADDED;
+ }
+
+ /**
+ * Expected command is "linkset link delete linkset1 link1"
+ *
+ * @param options
+ * @return
+ * @throws Exception
+ */
+ public String deleteLink(String[] options) throws Exception {
+
+ if (options == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
+
+ // The second last option is Linkset name
+ String linksetName = options[(options.length - 2)];
+
+ if (linksetName == null) {
+ throw new Exception(LinkOAMMessages.INVALID_COMMAND);
+ }
+ Linkset linkset = this.linksets.get(linksetName);
+
+ if (linkset == null) {
+ throw new Exception(LinkOAMMessages.LINKSET_DOESNT_EXIST);
+ }
+
+ // Last is Link name
+ linkset.deleteLink(options[(options.length - 1)]);
+
+ this.store();
+
+ return LinkOAMMessages.LINK_SUCCESSFULLY_REMOVED;
+ }
/**
* Persist
@@ -182,9 +288,9 @@
LinksetManager linkSetManager = new LinksetManager();
LinksetFactoryFactory linksetFactoryFactory = new
LinksetFactoryFactory();
-// linksetFactoryFactory.addFactory(new DahdiLinksetFactory());
-// linksetFactoryFactory.addFactory(new DialogicLinksetFactory());
-// linksetFactoryFactory.addFactory(new M3UALinksetFactory());
+ // linksetFactoryFactory.addFactory(new DahdiLinksetFactory());
+ // linksetFactoryFactory.addFactory(new DialogicLinksetFactory());
+ // linksetFactoryFactory.addFactory(new M3UALinksetFactory());
linkSetManager.setLinksetFactoryFactory(linksetFactoryFactory);