ASTERIXDB-1859 Revise create feed exception.
1. Fixed unknown feed datatype exception.
2. Revised SocketServerInputStreamFactory exception handling.
Change-Id: I4d04b3031a3457e4d04c2b921a4db3fd7f1cbed0
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1621
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Steven Jacobs <sjaco002@ucr.edu>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 28fd3d2..0c133ae 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -174,6 +174,9 @@
public static final int UTIL_LOCAL_FILE_SYSTEM_UTILS_PATH_NOT_FOUND = 3077;
public static final int UTIL_HDFS_UTILS_CANNOT_OBTAIN_HDFS_SCHEDULER = 3078;
public static final int ACTIVE_MANAGER_SHUTDOWN = 3079;
+ public static final int FEED_METADATA_UTIL_UNEXPECTED_FEED_DATATYPE = 3080;
+ public static final int FEED_METADATA_SOCKET_ADAPTOR_SOCKET_NOT_PROPERLY_CONFIGURED = 3081;
+ public static final int FEED_METADATA_SOCKET_ADAPTOR_SOCKET_INVALID_HOST_NC = 3082;
private ErrorCode() {
}
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 80a7981..6cf2a45 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -160,3 +160,6 @@
3077 = %1$s: path not found
3078 = Cannot obtain hdfs scheduler
3079 = Cannot register runtime, active manager has been shutdown
+3080 = Unexpected feed datatype '%1$s'
+3081 = socket is not properly configured.
+3082 = "Invalid %1$s %2$s as it is not part of the AsterixDB cluster. Valid choices are %3$s"
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/factory/SocketServerInputStreamFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/factory/SocketServerInputStreamFactory.java
index 6a581ef..f8aac81 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/factory/SocketServerInputStreamFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/factory/SocketServerInputStreamFactory.java
@@ -22,6 +22,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -29,6 +30,8 @@
import java.util.Set;
import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.external.api.AsterixInputStream;
import org.apache.asterix.external.api.IInputStreamFactory;
import org.apache.asterix.external.input.stream.SocketServerInputStream;
@@ -36,6 +39,7 @@
import org.apache.asterix.runtime.utils.RuntimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.common.utils.Pair;
import org.apache.hyracks.api.context.IHyracksTaskContext;
import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -52,7 +56,7 @@
}
@Override
- public void configure(Map<String, String> configuration) throws AsterixException {
+ public void configure(Map<String, String> configuration) throws AlgebricksException {
try {
sockets = new ArrayList<Pair<String, Integer>>();
String modeValue = configuration.get(ExternalDataConstants.KEY_MODE);
@@ -61,8 +65,7 @@
}
String socketsValue = configuration.get(ExternalDataConstants.KEY_SOCKETS);
if (socketsValue == null) {
- throw new IllegalArgumentException(
- "\'sockets\' parameter not specified as part of adapter configuration");
+ throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_NOT_PROPERLY_CONFIGURED);
}
Map<InetAddress, Set<String>> ncMap;
ncMap = RuntimeUtils.getNodeControllerMap();
@@ -78,9 +81,9 @@
case IP:
Set<String> ncsOnIp = ncMap.get(InetAddress.getByName(host));
if ((ncsOnIp == null) || ncsOnIp.isEmpty()) {
- throw new IllegalArgumentException("Invalid host " + host
- + " as it is not part of the AsterixDB cluster. Valid choices are "
- + StringUtils.join(ncMap.keySet(), ", "));
+ throw new CompilationException(
+ ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_INVALID_HOST_NC, "host", host,
+ StringUtils.join(ncMap.keySet(), ", "));
}
String[] ncArray = ncsOnIp.toArray(new String[] {});
String nc = ncArray[random.nextInt(ncArray.length)];
@@ -90,17 +93,21 @@
case NC:
p = new Pair<String, Integer>(host, port);
if (!ncs.contains(host)) {
- throw new IllegalArgumentException("Invalid NC " + host
- + " as it is not part of the AsterixDB cluster. Valid choices are "
- + StringUtils.join(ncs, ", "));
+ throw new CompilationException(
+ ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_INVALID_HOST_NC, "NC", host,
+ StringUtils.join(ncs, ", "));
}
break;
}
sockets.add(p);
}
- } catch (Exception e) {
+ } catch (CompilationException e) {
+ throw e;
+ } catch (HyracksDataException | UnknownHostException e) {
throw new AsterixException(e);
+ } catch (Exception e) {
+ throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_NOT_PROPERLY_CONFIGURED);
}
}
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
index 3e22e6e..45e358f 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
@@ -296,13 +296,12 @@
try {
ctx = MetadataManager.INSTANCE.beginTransaction();
Datatype t = MetadataManager.INSTANCE.getDatatype(ctx, dataverseName, datatypeName);
- IAType type = t.getDatatype();
- if (type.getTypeTag() != ATypeTag.RECORD) {
- throw new IllegalStateException();
+ if (t == null || t.getDatatype().getTypeTag() != ATypeTag.RECORD) {
+ throw new MetadataException(ErrorCode.FEED_METADATA_UTIL_UNEXPECTED_FEED_DATATYPE, datatypeName);
}
outputType = (ARecordType) t.getDatatype();
MetadataManager.INSTANCE.commitTransaction(ctx);
- } catch (ACIDException | RemoteException | MetadataException e) {
+ } catch (ACIDException | RemoteException e) {
if (ctx != null) {
try {
MetadataManager.INSTANCE.abortTransaction(ctx);