Merge from asterix_stabilization r1176:1182
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_issue_252_253@1183 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ADMCursor.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ADMCursor.java
deleted file mode 100644
index a48feba..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ADMCursor.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-import edu.uci.ics.asterix.om.base.ABinary;
-import edu.uci.ics.asterix.om.base.ABitArray;
-import edu.uci.ics.asterix.om.base.ABoolean;
-import edu.uci.ics.asterix.om.base.ACircle;
-import edu.uci.ics.asterix.om.base.ADate;
-import edu.uci.ics.asterix.om.base.ADateTime;
-import edu.uci.ics.asterix.om.base.ADouble;
-import edu.uci.ics.asterix.om.base.ADuration;
-import edu.uci.ics.asterix.om.base.AFloat;
-import edu.uci.ics.asterix.om.base.AInt16;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AInt64;
-import edu.uci.ics.asterix.om.base.AInt8;
-import edu.uci.ics.asterix.om.base.AInterval;
-import edu.uci.ics.asterix.om.base.ALine;
-import edu.uci.ics.asterix.om.base.APoint;
-import edu.uci.ics.asterix.om.base.APoint3D;
-import edu.uci.ics.asterix.om.base.APolygon;
-import edu.uci.ics.asterix.om.base.ARecord;
-import edu.uci.ics.asterix.om.base.ARectangle;
-import edu.uci.ics.asterix.om.base.AString;
-import edu.uci.ics.asterix.om.base.ATime;
-import edu.uci.ics.asterix.om.base.IACollection;
-import edu.uci.ics.asterix.om.base.IACursor;
-import edu.uci.ics.asterix.om.base.IAObject;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.IAType;
-
-/**
- * This class is the implementation of IADMCursor. This class supports iterating
- * over all objects in ASTERIX. All ASTERIX objects can be iterated over and
- * returned via the associated get<Type>() call.
- *
- * @author zheilbron
- */
-public class ADMCursor implements IADMCursor {
- protected IAObject currentObject;
- protected IACursor collectionCursor;
- private boolean readOnce;
-
- public ADMCursor(IAObject currentObject) {
- setCurrentObject(currentObject);
- }
-
- public boolean next() throws AQLJException {
- if (collectionCursor != null) {
- boolean next = collectionCursor.next();
- if (next) {
- currentObject = collectionCursor.get();
- }
- return next;
- } else if (currentObject == null) {
- return false;
- } else {
- if (!readOnce) {
- readOnce = true;
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void position(IADMCursor c) throws AQLJException {
- ((ADMCursor) c).setCurrentObject(currentObject);
- }
-
- @Override
- public void position(IADMCursor c, String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- ((ADMCursor) c).setCurrentObject(o);
- }
-
- private IAObject getObjectByField(String field) throws AQLJException {
- ATypeTag tag = currentObject.getType().getTypeTag();
- if (tag != ATypeTag.RECORD) {
- throw new AQLJException("object of type " + tag + " has no fields");
- }
- ARecord curRecord = (ARecord) currentObject;
- ARecordType t = curRecord.getType();
- int idx = t.findFieldPosition(field);
- if (idx == -1) {
- return null;
- }
- IAObject o = curRecord.getValueByPos(idx);
- return o;
- }
-
- public void setCurrentObject(IAObject o) {
- readOnce = false;
- currentObject = o;
- if (currentObject != null) {
- if (currentObject.getType() instanceof AbstractCollectionType) {
- collectionCursor = ((IACollection) currentObject).getCursor();
- }
- }
- }
-
- private void checkTypeTag(IAObject o, ATypeTag expectedTag) throws AQLJException {
- ATypeTag actualTag;
- actualTag = o.getType().getTypeTag();
-
- if (actualTag != expectedTag) {
- throw new AQLJException("cannot get " + expectedTag + " when type is " + actualTag);
- }
- }
-
- @Override
- public ABinary getBinary() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.BINARY);
- return ((ABinary) currentObject);
- }
-
- @Override
- public ABinary getBinary(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.BINARY);
- return (ABinary) o;
- }
-
- @Override
- public ABitArray getBitArray() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.BITARRAY);
- return ((ABitArray) currentObject);
- }
-
- @Override
- public ABitArray getBitArray(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.BITARRAY);
- return (ABitArray) o;
- }
-
- @Override
- public ABoolean getBoolean() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.BOOLEAN);
- return ((ABoolean) currentObject);
- }
-
- @Override
- public ABoolean getBoolean(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.BOOLEAN);
- return (ABoolean) o;
- }
-
- @Override
- public ACircle getCircle() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.CIRCLE);
- return ((ACircle) currentObject);
- }
-
- @Override
- public ACircle getCircle(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.CIRCLE);
- return (ACircle) o;
- }
-
- @Override
- public ADate getDate() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.DATE);
- return ((ADate) currentObject);
- }
-
- @Override
- public ADate getDate(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.DATE);
- return (ADate) o;
- }
-
- @Override
- public ADateTime getDateTime() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.DATETIME);
- return ((ADateTime) currentObject);
- }
-
- @Override
- public ADateTime getDateTime(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.DATETIME);
- return (ADateTime) o;
- }
-
- @Override
- public ADouble getDouble() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.DOUBLE);
- return ((ADouble) currentObject);
- }
-
- @Override
- public ADouble getDouble(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.DOUBLE);
- return (ADouble) o;
- }
-
- @Override
- public ADuration getDuration() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.DURATION);
- return ((ADuration) currentObject);
- }
-
- @Override
- public ADuration getDuration(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.DURATION);
- return (ADuration) o;
- }
-
- @Override
- public AInterval getInterval() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.INTERVAL);
- return ((AInterval) currentObject);
- }
-
- @Override
- public AInterval getInterval(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.INTERVAL);
- return (AInterval) o;
- }
-
- @Override
- public AFloat getFloat() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.FLOAT);
- return ((AFloat) currentObject);
- }
-
- @Override
- public AFloat getFloat(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.FLOAT);
- return (AFloat) o;
- }
-
- @Override
- public AInt8 getInt8() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.INT8);
- return ((AInt8) currentObject);
- }
-
- @Override
- public AInt8 getInt8(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.INT8);
- return (AInt8) o;
- }
-
- @Override
- public AInt16 getInt16() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.INT16);
- return ((AInt16) currentObject);
- }
-
- @Override
- public AInt16 getInt16(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.INT16);
- return (AInt16) o;
- }
-
- @Override
- public AInt32 getInt32() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.INT32);
- return ((AInt32) currentObject);
- }
-
- @Override
- public AInt32 getInt32(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.INT32);
- return (AInt32) o;
- }
-
- @Override
- public AInt64 getInt64() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.INT64);
- return ((AInt64) currentObject);
- }
-
- @Override
- public AInt64 getInt64(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.INT64);
- return (AInt64) o;
- }
-
- @Override
- public ALine getLine() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.LINE);
- return ((ALine) currentObject);
- }
-
- @Override
- public ALine getLine(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.LINE);
- return (ALine) o;
- }
-
- @Override
- public APoint getPoint() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.POINT);
- return ((APoint) currentObject);
- }
-
- @Override
- public APoint getPoint(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.POINT);
- return (APoint) o;
- }
-
- @Override
- public APoint3D getPoint3D() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.POINT3D);
- return ((APoint3D) currentObject);
- }
-
- @Override
- public APoint3D getPoint3D(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.POINT3D);
- return (APoint3D) o;
- }
-
- @Override
- public APolygon getPolygon() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.POLYGON);
- return ((APolygon) currentObject);
- }
-
- @Override
- public APolygon getPolygon(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.POLYGON);
- return (APolygon) o;
- }
-
- @Override
- public ARectangle getRectangle() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.RECTANGLE);
- return ((ARectangle) currentObject);
- }
-
- @Override
- public ARectangle getRectangle(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.RECTANGLE);
- return (ARectangle) o;
- }
-
- @Override
- public AString getString() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.STRING);
- return ((AString) currentObject);
- }
-
- @Override
- public AString getString(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.STRING);
- return (AString) o;
- }
-
- @Override
- public ATime getTime() throws AQLJException {
- checkTypeTag(currentObject, ATypeTag.TIME);
- return ((ATime) currentObject);
- }
-
- @Override
- public ATime getTime(String field) throws AQLJException {
- IAObject o = getObjectByField(field);
- checkTypeTag(o, ATypeTag.TIME);
- return (ATime) o;
- }
-
- public IAType getType() {
- if (currentObject != null) {
- return currentObject.getType();
- }
- return null;
- }
-
- @Override
- public IAObject get() {
- return currentObject;
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJClientDriver.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJClientDriver.java
deleted file mode 100644
index a1a077b..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJClientDriver.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-
-/**
- * This class encapsulates the mechanism for creating a connection to an ASTERIX
- * server.
- *
- * @author zheilbron
- */
-public class AQLJClientDriver {
- /**
- * Get a connection to the ASTERIX server.
- *
- * @param host
- * the ip or hostname of the ASTERIX server
- * @param port
- * the port of the ASTERIX server (default: 14600)
- * @param dataverse
- * the name of the dataverse to use for any AQL statements
- * @return an IAQLJConnection object representing the connection to ASTERIX
- * @throws AQLJException
- */
- public static IAQLJConnection getConnection(String host, int port, String dataverse) throws AQLJException {
- return new AQLJConnection(host, port, dataverse);
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJConnection.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJConnection.java
deleted file mode 100644
index c597450..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJConnection.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import java.io.IOException;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJProtocol;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJStream;
-
-/**
- * This class is the implementation of IAQLJConnection and is the means for
- * communication between a client and an ASTERIX server. The messages passed
- * through this connection conform to the AQLJ protocol.
- *
- * @author zheilbron
- */
-public class AQLJConnection implements IAQLJConnection {
- private final String dataverse;
- private final AQLJStream aqljStream;
-
- public AQLJConnection(String host, int port, String dataverse) throws AQLJException {
- this.dataverse = dataverse;
-
- try {
- aqljStream = new AQLJStream(host, port);
- } catch (IOException e) {
- throw new AQLJException("Could not connect to " + host + ":" + port);
- }
-
- startup();
- }
-
- private void startup() throws AQLJException {
- sendStartupMessage(dataverse);
- getStartupResponse();
- }
-
- private void sendStartupMessage(String dataverse) throws AQLJException {
- try {
- byte[] dvBytes = dataverse.getBytes("UTF-8");
- // 4 for the message length, 1 for the message type, 2 for the
- // string length
- aqljStream.sendUnsignedInt32(4 + 1 + 2 + dvBytes.length);
- aqljStream.sendChar(AQLJProtocol.STARTUP_MESSAGE);
- aqljStream.sendInt16(dvBytes.length);
- aqljStream.send(dvBytes);
- aqljStream.flush();
- } catch (IOException e) {
- throw new AQLJException(e);
- }
- }
-
- private void getStartupResponse() throws AQLJException {
- try {
- aqljStream.receiveUnsignedInt32();
- int messageType = aqljStream.receiveChar();
- switch (messageType) {
- case AQLJProtocol.READY_MESSAGE:
- break;
- case AQLJProtocol.ERROR_MESSAGE:
- String err = aqljStream.receiveString();
- throw new AQLJException(err);
- default:
- throw new AQLJException("Error: unable to parse message from server");
- }
- } catch (IOException e) {
- throw new AQLJException(e);
- }
- }
-
- @Override
- public IAQLJResult execute(String stmt) throws AQLJException {
- sendExecute(stmt);
- return fetchResults();
- }
-
- private AQLJResult fetchResults() throws AQLJException {
- long len;
- int messageType;
-
- ResultBuffer rb = null;
- while (true) {
- try {
- len = aqljStream.receiveUnsignedInt32();
- messageType = aqljStream.receiveChar();
- switch (messageType) {
- case AQLJProtocol.DATA_MESSAGE:
- // DataRecord
- if (rb == null) {
- rb = new ResultBuffer();
- }
- rb.appendMessage(aqljStream, (int) (len - 5));
- break;
- case AQLJProtocol.EXECUTE_COMPLETE_MESSAGE:
- // ExecuteComplete
- return new AQLJResult(rb);
- case AQLJProtocol.ERROR_MESSAGE:
- // Error
- throw new AQLJException(aqljStream.receiveString());
- default:
- throw new AQLJException("Error: received unknown message type from server");
- }
- } catch (IOException e) {
- throw new AQLJException(e);
- }
- }
-
- }
-
- private void sendExecute(String stmt) throws AQLJException {
- try {
- byte[] stmtBytes = stmt.getBytes("UTF-8");
- // 4 for the message length, 1 for the message type, 2 for the
- // string length
- aqljStream.sendUnsignedInt32(4 + 1 + 2 + stmtBytes.length);
- aqljStream.sendChar(AQLJProtocol.EXECUTE_MESSAGE);
- aqljStream.sendInt16(stmtBytes.length);
- aqljStream.send(stmtBytes);
- aqljStream.flush();
- } catch (IOException e) {
- throw new AQLJException(e);
- }
- }
-
- @Override
- public void close() throws IOException {
- aqljStream.close();
- }
-
- @Override
- public IADMCursor createADMCursor() {
- return new ADMCursor(null);
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJResult.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJResult.java
deleted file mode 100644
index 63114ce..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/AQLJResult.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import java.io.IOException;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-
-/**
- * This class is special type of ADMCursor in that it has a result buffer
- * associated with it. It can be thought of as the "base" cursor for some ADM
- * results.
- *
- * @author zheilbron
- */
-public class AQLJResult extends ADMCursor implements IAQLJResult {
- private final ResultBuffer resultBuffer;
-
- public AQLJResult(ResultBuffer buffer) {
- super(null);
- this.resultBuffer = buffer;
- }
-
- @Override
- public boolean next() throws AQLJException {
- currentObject = resultBuffer.get();
- if (currentObject == null) {
- return false;
- }
- return true;
- }
-
- public void close() throws IOException {
- resultBuffer.close();
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IADMCursor.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IADMCursor.java
deleted file mode 100644
index 51318a1..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IADMCursor.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-import edu.uci.ics.asterix.om.base.ABinary;
-import edu.uci.ics.asterix.om.base.ABitArray;
-import edu.uci.ics.asterix.om.base.ABoolean;
-import edu.uci.ics.asterix.om.base.ACircle;
-import edu.uci.ics.asterix.om.base.ADate;
-import edu.uci.ics.asterix.om.base.ADateTime;
-import edu.uci.ics.asterix.om.base.ADouble;
-import edu.uci.ics.asterix.om.base.ADuration;
-import edu.uci.ics.asterix.om.base.AFloat;
-import edu.uci.ics.asterix.om.base.AInt16;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AInt64;
-import edu.uci.ics.asterix.om.base.AInt8;
-import edu.uci.ics.asterix.om.base.AInterval;
-import edu.uci.ics.asterix.om.base.ALine;
-import edu.uci.ics.asterix.om.base.APoint;
-import edu.uci.ics.asterix.om.base.APoint3D;
-import edu.uci.ics.asterix.om.base.APolygon;
-import edu.uci.ics.asterix.om.base.ARectangle;
-import edu.uci.ics.asterix.om.base.AString;
-import edu.uci.ics.asterix.om.base.ATime;
-import edu.uci.ics.asterix.om.base.IAObject;
-import edu.uci.ics.asterix.om.types.IAType;
-
-/**
- * The mechanism by which results are iterated over. Results from ASTERIX may
- * come in the form of a set of objects which may either be primitives (e.g.
- * int, string, ...), collections (e.g. ordered lists, unordered lists, ...),
- * records, or some combination thereof.
- *
- * @author zheilbron
- */
-public interface IADMCursor {
- public ABinary getBinary() throws AQLJException;
-
- public ABinary getBinary(String field) throws AQLJException;
-
- public ABitArray getBitArray() throws AQLJException;
-
- public ABitArray getBitArray(String field) throws AQLJException;
-
- public ABoolean getBoolean() throws AQLJException;
-
- public ABoolean getBoolean(String field) throws AQLJException;
-
- public ACircle getCircle() throws AQLJException;
-
- public ACircle getCircle(String field) throws AQLJException;
-
- public ADate getDate() throws AQLJException;
-
- public ADate getDate(String field) throws AQLJException;
-
- public ADateTime getDateTime() throws AQLJException;
-
- public ADateTime getDateTime(String field) throws AQLJException;
-
- public ADouble getDouble() throws AQLJException;
-
- public ADouble getDouble(String field) throws AQLJException;
-
- public ADuration getDuration() throws AQLJException;
-
- public ADuration getDuration(String field) throws AQLJException;
-
- public AInterval getInterval() throws AQLJException;
-
- public AInterval getInterval(String field) throws AQLJException;
-
- public AFloat getFloat() throws AQLJException;
-
- public AFloat getFloat(String field) throws AQLJException;
-
- public AInt8 getInt8() throws AQLJException;
-
- public AInt8 getInt8(String field) throws AQLJException;
-
- public AInt16 getInt16() throws AQLJException;
-
- public AInt16 getInt16(String field) throws AQLJException;
-
- public AInt32 getInt32() throws AQLJException;
-
- public AInt32 getInt32(String field) throws AQLJException;
-
- public AInt64 getInt64() throws AQLJException;
-
- public AInt64 getInt64(String field) throws AQLJException;
-
- public ALine getLine() throws AQLJException;
-
- public ALine getLine(String field) throws AQLJException;
-
- public APoint getPoint() throws AQLJException;
-
- public APoint getPoint(String field) throws AQLJException;
-
- public APoint3D getPoint3D() throws AQLJException;
-
- public APoint3D getPoint3D(String field) throws AQLJException;
-
- public APolygon getPolygon() throws AQLJException;
-
- public APolygon getPolygon(String field) throws AQLJException;
-
- public ARectangle getRectangle() throws AQLJException;
-
- public ARectangle getRectangle(String field) throws AQLJException;
-
- public AString getString(String field) throws AQLJException;
-
- public AString getString() throws AQLJException;
-
- public ATime getTime() throws AQLJException;
-
- public ATime getTime(String field) throws AQLJException;
-
- /**
- * Advances the cursor to the next object
- *
- * @return true if the cursor points to a an object
- * @throws AQLJException
- */
- public boolean next() throws AQLJException;
-
- /**
- * Positions the cursor c on the object pointed to by this
- *
- * @param c
- * the cursor to position
- * @throws AQLJException
- */
- public void position(IADMCursor c) throws AQLJException;
-
- /**
- * Positions the cursor c on the object associated with the given field
- *
- * @param c
- * the cursor to position
- * @param field
- * the field name
- * @throws AQLJException
- */
- public void position(IADMCursor c, String field) throws AQLJException;
-
- /**
- * Returns the type of the current object being pointed at, which may be
- * null.
- *
- * @return the type of the current object
- */
- public IAType getType();
-
- /**
- * Returns the current object being pointed at, which may be null.
- *
- * @return the current object
- */
- public IAObject get();
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJConnection.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJConnection.java
deleted file mode 100644
index 8fdf59d..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJConnection.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import java.io.IOException;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-
-/**
- * The connection (session) that serves as the context for communicating with
- * ASTERIX.
- *
- * @author zheilbron
- */
-public interface IAQLJConnection {
- /**
- * Execute an AQL statement that returns an IAQLJResult. The IAQLJResult
- * will contain all associated results of the AQL statement.
- *
- * @param stmt
- * the AQL statement
- * @return the results of the AQL statement as an IAQLJResult
- * @throws AQLJException
- */
- public IAQLJResult execute(String stmt) throws AQLJException;
-
- /**
- * Create a cursor to iterate over results
- *
- * @return an unpositioned cursor
- */
- public IADMCursor createADMCursor();
-
- /**
- * Close the connection with the server.
- */
- public void close() throws IOException;
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJResult.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJResult.java
deleted file mode 100644
index b28b3c6..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/IAQLJResult.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import java.io.IOException;
-
-/**
- * The results associated with an AQL statement.
- *
- * @author zheilbron
- */
-public interface IAQLJResult extends IADMCursor {
- /**
- * Close the cursor and discard any associated results.
- * It's important to ensure that this method is called in order to free up
- * the associated result buffer.
- */
- public void close() throws IOException;
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ResultBuffer.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ResultBuffer.java
deleted file mode 100644
index 9fddad5..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/client/ResultBuffer.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.client;
-
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.util.logging.Logger;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJStream;
-import edu.uci.ics.asterix.om.base.IAObject;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
-import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-
-/**
- * This class supports the buffering of results that are received from the
- * server. The results are buffered completely to a file on disk. The results
- * that are sent back should contain a serde in order to read the results back
- * in. To see the expected format refer to {@link edu.uci.ics.algebricks.runtime.hyracks.writers.SerializedDataWriterFactory} .
- *
- * @author zheilbron
- */
-public class ResultBuffer {
- private static final Logger LOGGER = Logger.getLogger(ResultBuffer.class.getName());
-
- private static final int BUF_SIZE = 8192;
-
- private final byte[] buffer;
- private final File tmpFile;
- private final FileOutputStream fos;
- private final FileInputStream fis;
- private final DataInputStream dis;
-
- private ObjectInputStream ois;
- private ISerializerDeserializer serde;
-
- public ResultBuffer() throws IOException {
- buffer = new byte[BUF_SIZE];
- tmpFile = File.createTempFile("aqlj", null, new File(System.getProperty("java.io.tmpdir")));
- fos = new FileOutputStream(tmpFile);
- fis = new FileInputStream(tmpFile);
- dis = new DataInputStream(fis);
- serde = null;
- }
-
- private RecordDescriptor getRecordDescriptor() throws AQLJException {
- RecordDescriptor rd;
- try {
- ois = new ObjectInputStream(fis);
- } catch (IOException e) {
- throw new AQLJException(e);
- }
- try {
- rd = (RecordDescriptor) ois.readObject();
- } catch (IOException e) {
- throw new AQLJException(e);
- } catch (ClassNotFoundException e) {
- throw new AQLJException(e);
- }
- return rd;
- }
-
- public IAObject get() throws AQLJException {
- Object o;
-
- if (serde == null) {
- serde = getRecordDescriptor().getFields()[0];
- }
-
- try {
- o = serde.deserialize(dis);
- } catch (HyracksDataException e) {
- // this is expected behavior... we know when we've reached the end
- // of the
- // results when a EOFException (masked by the HyracksDataException)
- // is thrown
- o = null;
- }
-
- return (IAObject) o;
- }
-
- public void appendMessage(AQLJStream aqljStream, long len) throws IOException {
- long pos = 0;
- long read = 0;
- long remaining = 0;
-
- while (pos < len) {
- remaining = len - pos;
- read = remaining > BUF_SIZE ? BUF_SIZE : remaining;
- aqljStream.receive(buffer, 0, (int) read);
- pos += read;
- fos.write(buffer, 0, (int) read);
- }
- }
-
- public void close() throws IOException {
- // remove the file!
- if (tmpFile.exists()) {
- tmpFile.delete();
- }
- fos.close();
- fis.close();
- dis.close();
- if (ois != null) {
- ois.close();
- }
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJException.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJException.java
deleted file mode 100644
index 7c19a56..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.common;
-
-/**
- * This is the base (and currently the only) exception class for AQLJ.
- *
- * @author zheilbron
- */
-public class AQLJException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public AQLJException(String message) {
- super(message);
- }
-
- public AQLJException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public AQLJException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJProtocol.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJProtocol.java
deleted file mode 100644
index 83ef0e5..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJProtocol.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.common;
-
-/**
- * This class provides constants for message types in the AQLJ protocol.
- *
- * @author zheilbron
- */
-public abstract class AQLJProtocol {
- public static final char STARTUP_MESSAGE = 'S';
- public static final char EXECUTE_MESSAGE = 'X';
- public static final char READY_MESSAGE = 'R';
- public static final char ERROR_MESSAGE = 'E';
- public static final char EXECUTE_COMPLETE_MESSAGE = 'C';
- public static final char DATA_MESSAGE = 'D';
- public static final char GET_RESULTS_MESSAGE = 'G';
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJStream.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJStream.java
deleted file mode 100644
index c595284..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/common/AQLJStream.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.common;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.net.Socket;
-
-/**
- * This class provides a clean mechanism for sending and receiving the data
- * types involved in the AQLJ protocol.
- *
- * @author zheilbron
- */
-public class AQLJStream {
- private static final int BUF_SIZE = 8192;
-
- private final String host;
- private final int port;
- private final Socket connection;
- private final BufferedInputStream aqljInput;
- private final BufferedOutputStream aqljOutput;
-
- private final byte[] int16Buf;
- private final byte[] int32Buf;
-
- public AQLJStream(String host, int port) throws IOException {
- this.host = host;
- this.port = port;
-
- connection = new Socket(host, port);
-
- aqljInput = new BufferedInputStream(connection.getInputStream(), BUF_SIZE);
- aqljOutput = new BufferedOutputStream(connection.getOutputStream(), BUF_SIZE);
-
- int16Buf = new byte[2];
- int32Buf = new byte[4];
- }
-
- public AQLJStream(Socket sock) throws IOException {
- this.host = null;
- this.port = 0;
-
- this.connection = sock;
- aqljInput = new BufferedInputStream(connection.getInputStream(), BUF_SIZE);
- aqljOutput = new BufferedOutputStream(connection.getOutputStream(), BUF_SIZE);
-
- int16Buf = new byte[2];
- int32Buf = new byte[4];
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
- public Socket getSocket() {
- return connection;
- }
-
- public void receive(byte[] buf, int off, int len) throws IOException {
- int read;
- int count = 0;
- while (count < len) {
- read = aqljInput.read(buf, off + count, len - count);
- if (read < 0) {
- throw new EOFException();
- }
- count += read;
- }
- }
-
- public byte[] receive(int len) throws IOException {
- byte[] result = new byte[len];
- receive(result, 0, len);
- return result;
- }
-
- public int receiveInt16() throws IOException {
- if (aqljInput.read(int16Buf) != 2) {
- throw new EOFException();
- }
- return (int16Buf[0] & 0xff) << 8 | (int16Buf[1] & 0xff);
- }
-
- public long receiveUnsignedInt32() throws IOException {
- if (aqljInput.read(int32Buf) != 4) {
- throw new EOFException();
- }
- return ((int32Buf[0] & 0xff) << 24 | (int32Buf[1] & 0xff) << 16 | (int32Buf[2] & 0xff) << 8 | (int32Buf[3] & 0xff)) & 0x00000000ffffffffl;
- }
-
- public int receiveChar() throws IOException {
- int c = aqljInput.read();
- if (c < 0) {
- throw new EOFException();
- }
- return c;
- }
-
- public String receiveString() throws IOException {
- int strlen = receiveInt16();
- return new String(receive(strlen), "UTF8");
- }
-
- public void send(byte[] buf) throws IOException {
- aqljOutput.write(buf);
- }
-
- public void send(byte[] buf, int off, int len) throws IOException {
- aqljOutput.write(buf, off, len);
- }
-
- public void sendInt16(int val) throws IOException {
- int16Buf[0] = (byte) (val >>> 8);
- int16Buf[1] = (byte) (val);
- aqljOutput.write(int16Buf);
- }
-
- public void sendUnsignedInt32(long val) throws IOException {
- int32Buf[0] = (byte) (val >>> 24);
- int32Buf[1] = (byte) (val >>> 16);
- int32Buf[2] = (byte) (val >>> 8);
- int32Buf[3] = (byte) (val);
- aqljOutput.write(int32Buf);
- }
-
- public void sendChar(int c) throws IOException {
- aqljOutput.write(c);
- }
-
- public void sendString(byte[] strBytes) throws IOException {
- sendInt16(strBytes.length);
- send(strBytes);
- }
-
- public void sendString(String str) throws IOException {
- byte[] strBytes = str.getBytes("UTF8");
- sendInt16(strBytes.length);
- send(strBytes);
- }
-
- public void flush() throws IOException {
- aqljOutput.flush();
- }
-
- public void close() throws IOException {
- aqljInput.close();
- aqljOutput.close();
- connection.close();
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThread.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThread.java
deleted file mode 100644
index 9879a2d..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThread.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJProtocol;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJStream;
-import edu.uci.ics.asterix.api.common.APIFramework.DisplayFormat;
-import edu.uci.ics.asterix.api.common.AsterixHyracksIntegrationUtil;
-import edu.uci.ics.asterix.api.common.SessionConfig;
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.parser.AQLParser;
-import edu.uci.ics.asterix.aql.parser.ParseException;
-import edu.uci.ics.asterix.aql.translator.AqlTranslator;
-import edu.uci.ics.asterix.aql.translator.QueryResult;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.hyracks.bootstrap.AsterixNodeState;
-import edu.uci.ics.asterix.metadata.MetadataManager;
-import edu.uci.ics.asterix.metadata.api.IAsterixStateProxy;
-import edu.uci.ics.asterix.metadata.bootstrap.AsterixProperties;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.api.application.ICCApplicationContext;
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-
-/**
- * This class is the client handler for the APIServer. The AQLJ protocol is used
- * for communicating with the client. The client, for example, may send a
- * message to execute a set containing one or more AQL statements. It is up to this class to process each
- * AQL statement (in the original order) and pass back the results, if any, to the client.
- *
- * @author zheilbron
- */
-public class APIClientThread extends Thread {
- private static final Logger LOGGER = Logger.getLogger(APIClientThread.class.getName());
-
- private static final int RESULT_BUF_SIZE = 8192;
-
- private final IHyracksClientConnection hcc;
- private final ICCApplicationContext appContext;
- private final AQLJStream clientStream;
- private final String outputFilePath;
- private final String outputNodeName;
- private final String outputNodeIP;
- private final String binaryOutputClause;
-
- private AQLJStream nodeDataServerStream;
- private int nodeDataServerPort;
- private String dataverse;
-
- public APIClientThread(IHyracksClientConnection hcc, Socket clientSocket, ICCApplicationContext appCtx)
- throws IOException {
- this.hcc = hcc;
- clientStream = new AQLJStream(clientSocket);
- this.appContext = appCtx;
-
- // get the name of the first node controller that we find
- // all query results will be written to this node
- Map<String, Set<String>> nodeNameMap = new HashMap<String, Set<String>>();
- try {
- this.appContext.getCCContext().getIPAddressNodeMap(nodeNameMap);
- } catch (Exception e) {
- throw new IOException(" unable to obtain IP address node map", e);
- }
- outputNodeIP = (String) nodeNameMap.keySet().toArray()[0];
- outputNodeName = (String) nodeNameMap.get(outputNodeIP).toArray()[0];
-
- // get the port of the node data server that is running on the first nc
- IAsterixStateProxy proxy = (IAsterixStateProxy) appCtx.getDistributedState();
- nodeDataServerPort = ((AsterixNodeState) proxy.getAsterixNodeState(outputNodeName)).getAPINodeDataServerPort();
- nodeDataServerStream = null;
-
- // write the data into the output stores directory of the nc
- // if output stores are unavailable (could they ever be?), then write to
- // tmpdir which can be overridden
- // Also, use milliseconds in path name of output file to differentiate
- // queries
- Map<String, String[]> storesMap = AsterixProperties.INSTANCE.getStores();
- String[] outputStores = storesMap.get(outputNodeName);
- if (outputStores.length > 0) {
- outputFilePath = outputStores[0] + System.currentTimeMillis() + ".adm";
- } else {
- outputFilePath = System.getProperty("java.io.tmpdir") + File.pathSeparator + System.currentTimeMillis()
- + ".adm";
- }
-
- // the "write output..." clause is inserted into incoming AQL statements
- binaryOutputClause = "write output to " + outputNodeName + ":\"" + outputFilePath
- + "\" using \"edu.uci.ics.hyracks.algebricks.runtime.writers.SerializedDataWriterFactory\";";
-
- }
-
- private void startup() throws IOException {
- int messageType;
-
- clientStream.receiveUnsignedInt32();
- messageType = clientStream.receiveChar();
- dataverse = clientStream.receiveString();
- if (messageType == AQLJProtocol.STARTUP_MESSAGE) {
- // send Ready
- sendReady();
- } else {
- // send Error
- LOGGER.warning("Error: received message other than Startup. Exiting.");
- String err = "startup failed: no Startup message received";
- sendError(err);
- }
- }
-
- public void run() {
- String outputPath;
- int messageType;
-
- try {
- // startup phase
- startup();
-
- // normal execution phase
- while (true) {
- // check if we should close
- if (Thread.interrupted()) {
- close();
- return;
- }
-
- clientStream.receiveUnsignedInt32();
- messageType = clientStream.receiveChar();
- switch (messageType) {
- case AQLJProtocol.EXECUTE_MESSAGE:
- // Execute
- String query = clientStream.receiveString();
- String fullQuery = "use dataverse " + dataverse + ";\n" + binaryOutputClause + '\n' + query;
-
- try {
- outputPath = executeStatement(fullQuery);
- } catch (AQLJException e) {
- LOGGER.severe("Error occurred while executing query: " + fullQuery);
- LOGGER.severe(e.getMessage());
- sendError(e.getMessage());
- break;
- }
-
- if (outputPath == null) {
- // The query ran, but produced no results. This
- // means cardinality of the
- // result is 0 or "actions" were performed, where
- // actions are things like create
- // type, create dataset, etc.
- sendExecuteComplete();
- } else {
- // otherwise, there are some results, so send them
- // back to the client
- if (sendResults(outputPath)) {
- sendExecuteComplete();
- } else {
- String err = "Error: unable to retrieve results from " + outputNodeName;
- LOGGER.severe(err);
- sendError(err);
- }
- }
- break;
- default:
- String err = "Error: received unknown message of type " + (char) messageType;
- sendError(err);
- LOGGER.severe(err);
- close();
- return;
- }
- }
- } catch (IOException e) {
- // the normal path that is taken when exiting
- close();
- return;
- }
- }
-
- private void close() {
- try {
- if (nodeDataServerStream != null) {
- nodeDataServerStream.close();
- }
- } catch (IOException e) {
- LOGGER.severe("Error closing NodeData AQLJStream");
- LOGGER.severe(e.getMessage());
- }
- try {
- clientStream.close();
- } catch (IOException e) {
- LOGGER.severe("Error closing client AQLJStream");
- LOGGER.severe(e.getMessage());
- }
- }
-
- private String executeStatement(String stmt) throws IOException, AQLJException {
- List<QueryResult> executionResults = null;
- PrintWriter out = new PrintWriter(System.out);
- try {
- AQLParser parser = new AQLParser(new StringReader(stmt));
- List<Statement> statements = parser.Statement();
- SessionConfig pc = new SessionConfig(AsterixHyracksIntegrationUtil.DEFAULT_HYRACKS_CC_CLIENT_PORT, true,
- false, false, false, false, false, true, false);
-
- MetadataManager.INSTANCE.init();
- if (statements != null && statements.size() > 0) {
- AqlTranslator translator = new AqlTranslator(statements, out, pc, DisplayFormat.TEXT);
- executionResults = translator.compileAndExecute(hcc);
- }
- } catch (ParseException e) {
- e.printStackTrace();
- throw new AQLJException(e);
- } catch (AsterixException e) {
- e.printStackTrace();
- throw new AQLJException(e);
- } catch (AlgebricksException e) {
- e.printStackTrace();
- throw new AQLJException(e);
- } catch (Exception e) {
- e.printStackTrace();
- sendError(e.getMessage());
- }
- return executionResults.get(0).getResultPath();
-
- }
-
- private boolean sendResults(String path) throws IOException {
- int messageType;
- long len;
- int sent;
- int toSend;
- byte[] buf = new byte[RESULT_BUF_SIZE];
-
- if (nodeDataServerStream == null) {
- nodeDataServerStream = new AQLJStream(outputNodeIP, nodeDataServerPort);
- }
- sendGetResults(nodeDataServerStream);
-
- // forward data packets from the nodedataservers through this server to
- // the client
- while (true) {
- len = nodeDataServerStream.receiveUnsignedInt32();
- messageType = nodeDataServerStream.receiveChar();
- switch ((char) messageType) {
- case AQLJProtocol.DATA_MESSAGE:
- clientStream.sendUnsignedInt32(len);
- clientStream.sendChar(AQLJProtocol.DATA_MESSAGE);
- len -= 5;
- sent = 0;
- while (sent < len) {
- len -= sent;
- toSend = (len > buf.length) ? buf.length : (int) len;
- nodeDataServerStream.receive(buf, 0, toSend);
- clientStream.send(buf, 0, toSend);
- sent += toSend;
- }
- clientStream.flush();
- break;
- case AQLJProtocol.EXECUTE_COMPLETE_MESSAGE:
- nodeDataServerStream.close();
- nodeDataServerStream = null;
- return true;
- default:
- nodeDataServerStream.close();
- nodeDataServerStream = null;
- return false;
- }
- }
- }
-
- private void sendGetResults(AQLJStream s) throws IOException {
- byte[] pathBytes = outputFilePath.getBytes("UTF-8");
- // 4 for the message length, 1 for the message type, 2 for the string
- // length
- s.sendUnsignedInt32(4 + 1 + 2 + pathBytes.length);
- s.sendChar(AQLJProtocol.GET_RESULTS_MESSAGE);
- s.sendString(outputFilePath);
- s.flush();
- }
-
- private void sendReady() throws IOException {
- // 4 for the message length and 1 for the message type (4 + 1 = 5)
- clientStream.sendUnsignedInt32(5);
- clientStream.sendChar(AQLJProtocol.READY_MESSAGE);
- clientStream.flush();
- }
-
- private void sendError(String msg) throws IOException {
- byte[] msgBytes = msg.getBytes("UTF-8");
- // 4 for the message length, 1 for the message type, 2 for the string
- // length
- clientStream.sendUnsignedInt32(4 + 1 + 2 + msgBytes.length);
- clientStream.sendChar(AQLJProtocol.ERROR_MESSAGE);
- clientStream.sendInt16(msgBytes.length);
- clientStream.send(msgBytes);
- clientStream.flush();
- }
-
- private void sendExecuteComplete() throws IOException {
- // 4 for the message length and 1 for the message type (4 + 1 = 5)
- clientStream.sendUnsignedInt32(5);
- clientStream.sendChar(AQLJProtocol.EXECUTE_COMPLETE_MESSAGE);
- clientStream.flush();
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThreadFactory.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThreadFactory.java
deleted file mode 100644
index 7f35af6..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/APIClientThreadFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.IOException;
-import java.net.Socket;
-
-import edu.uci.ics.hyracks.api.application.ICCApplicationContext;
-import edu.uci.ics.hyracks.api.client.HyracksConnection;
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-
-/**
- * This class is a factory for client handler threads of type {@link APIClientThread} and is used in conjunction with {@link ThreadedServer}.
- *
- * @author zheilbron
- */
-public class APIClientThreadFactory implements IClientThreadFactory {
- private final ICCApplicationContext appContext;
-
- private IHyracksClientConnection hcc;
-
- public APIClientThreadFactory(ICCApplicationContext appContext) throws Exception {
- this.appContext = appContext;
- hcc = new HyracksConnection(appContext.getCCContext().getClusterControllerInfo().getClientNetAddress(), appContext.getCCContext().getClusterControllerInfo()
- .getClientNetPort());
- }
-
- @Override
- public Thread createThread(Socket socket) throws IOException {
- return new APIClientThread(hcc, socket, appContext);
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/IClientThreadFactory.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/IClientThreadFactory.java
deleted file mode 100644
index bca7f4d..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/IClientThreadFactory.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.IOException;
-import java.net.Socket;
-
-/**
- * Implementing this interface allows a class such as {@link ThreadedServer} to
- * spawn a particular type of thread to handle some client connection.
- *
- * @author zheilbron
- */
-public interface IClientThreadFactory {
- public Thread createThread(Socket socket) throws IOException;
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThread.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThread.java
deleted file mode 100644
index 0246fd9..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThread.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.Socket;
-import java.util.logging.Logger;
-
-import edu.uci.ics.asterix.api.aqlj.common.AQLJProtocol;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJStream;
-
-/**
- * This class handles data requests from the APIServer. When a query is executed
- * through the API, the output is written to the local disk of some NC. The
- * APIServer will contact that NC and ask for the results of the query to be
- * sent. This class handles such communication between the NC and APIServer.
- *
- * @author zheilbron
- */
-public class NodeDataClientThread extends Thread {
- private static final Logger LOGGER = Logger.getLogger(NodeDataClientThread.class.getName());
-
- private static final int RESULT_BUFFER_SIZE = 8192;
-
- private final AQLJStream aqljStream;
-
- public NodeDataClientThread(Socket clientSocket) throws IOException {
- aqljStream = new AQLJStream(clientSocket);
- }
-
- public void run() {
- try {
- getFile();
- } catch (IOException e) {
- LOGGER.severe("I/O error occurred over AQLJStream (socket)");
- LOGGER.severe(e.getMessage());
- } finally {
- close();
- }
- }
-
- private void getFile() throws IOException {
- aqljStream.receiveUnsignedInt32();
- int type = aqljStream.receiveChar();
- if ((char) type != AQLJProtocol.GET_RESULTS_MESSAGE) {
- return;
- }
-
- String path = aqljStream.receiveString();
- File outputFile = new File(path);
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(outputFile);
- } catch (FileNotFoundException e) {
- LOGGER.warning("Error: requested file not found: " + path);
- return;
- }
-
- byte[] buf = new byte[RESULT_BUFFER_SIZE];
- long maxPayload = 0xffffffffL - 5; // 2^32 (max size of payload) - 5
- // (header size)
- long remainingTotal = outputFile.length();
- long remainingInner = 0;
- int sentTotal = 0;
- int sentInner = 0;
- int toSend = 0;
-
- // the results may be large, so cram as much into a packet as possible
- while (remainingTotal > maxPayload) {
- aqljStream.sendUnsignedInt32(4 + 1 + maxPayload);
- aqljStream.sendChar(AQLJProtocol.DATA_MESSAGE);
- sentInner = 0;
- remainingInner = 0;
- while (sentInner < maxPayload) {
- remainingInner = maxPayload - sentInner;
- toSend = fis.read(buf, 0, (remainingInner > buf.length) ? buf.length : (int) remainingInner);
- sentInner += toSend;
- aqljStream.send(buf, 0, toSend);
- }
- aqljStream.flush();
- sentTotal += maxPayload;
- remainingTotal -= sentTotal;
- }
-
- // send the remaining data
- if (remainingTotal > 0) {
- aqljStream.sendUnsignedInt32(4 + 1 + (int) remainingTotal);
- aqljStream.sendChar(AQLJProtocol.DATA_MESSAGE);
- sentInner = 0;
- remainingInner = 0;
- while (sentInner < remainingTotal) {
- remainingInner = remainingTotal - sentInner;
- toSend = fis.read(buf, 0, (remainingInner > buf.length) ? buf.length : (int) remainingInner);
- sentInner += toSend;
- aqljStream.send(buf, 0, toSend);
- }
- aqljStream.flush();
- }
- outputFile.delete();
- aqljStream.sendUnsignedInt32(5);
- aqljStream.sendChar(AQLJProtocol.EXECUTE_COMPLETE_MESSAGE);
- aqljStream.flush();
- }
-
- private void close() {
- try {
- aqljStream.close();
- } catch (IOException e) {
- LOGGER.severe("Error closing AQLJStream");
- LOGGER.severe(e.getMessage());
- }
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThreadFactory.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThreadFactory.java
deleted file mode 100644
index 22efa89..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/NodeDataClientThreadFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.IOException;
-import java.net.Socket;
-
-/**
- * This class is a factory for client handler threads of type {@link NodeDataClientThread} and is used in conjunction with {@link ThreadedServer}.
- *
- * @author zheilbron
- */
-public class NodeDataClientThreadFactory implements IClientThreadFactory {
- @Override
- public Thread createThread(Socket socket) throws IOException {
- return new NodeDataClientThread(socket);
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/ThreadedServer.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/ThreadedServer.java
deleted file mode 100644
index 573d6a3..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/aqlj/server/ThreadedServer.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.aqlj.server;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketException;
-import java.util.logging.Logger;
-
-/**
- * This server is a multithreaded server that spawns one connection per client
- * up to MAX_CLIENTS total clients. The type of thread spawned to handle each
- * client request is delegated to a client thread factory that implements the
- * IClientThreadFactory interface.
- * NOTE: The "BE" in logging messages stands for "back-end". This is to
- * differentiate from the "FE" or "front-end" when reviewing log messages.
- *
- * @author zheilbron
- */
-public class ThreadedServer extends Thread {
- private static Logger LOGGER = Logger.getLogger(ThreadedServer.class.getName());
-
- private static final int MAX_CLIENTS = 10;
-
- private final int port;
- private final IClientThreadFactory factory;
-
- private ServerSocket serverSocket;
- private Socket clientSocket;
- private Socket[] clientSockets;
- private Thread[] threads;
-
- public ThreadedServer(int port, IClientThreadFactory factory) {
- this.port = port;
- this.factory = factory;
- this.clientSockets = new Socket[MAX_CLIENTS];
- this.threads = new Thread[MAX_CLIENTS];
- this.clientSocket = null;
- }
-
- public void run() {
- try {
- serverSocket = new ServerSocket(port);
- } catch (IOException e) {
- LOGGER.severe("Error listening on port: " + port);
- LOGGER.severe(e.getMessage());
- return;
- }
- LOGGER.info("Server started. Listening on port: " + port);
-
- while (true) {
- try {
- clientSocket = serverSocket.accept();
- } catch (SocketException e) {
- // This is the normal path the server will take when exiting.
- //
- // In order to close the server down properly, the
- // serverSocket.accept() call must
- // be interrupted. The only way to interrupt the
- // serverSocket.accept() call in the loop
- // above is by calling serverSocket.close() (as is done in the
- // ThreadedServer.shutdown() method
- // below). The serverSocket.accept() then throws a
- // SocketException, so we catch it here
- // and assume that ThreadedServer.shutdown() was called.
-
- return;
- } catch (IOException e) {
- LOGGER.severe("Failed to accept() connection");
- LOGGER.severe(e.getMessage());
- }
-
- for (int i = 0; i < threads.length; i++) {
- if (threads[i] == null || !threads[i].isAlive()) {
- try {
- threads[i] = factory.createThread(clientSocket);
- } catch (IOException e) {
- LOGGER.severe("Failed to create client handler thread");
- LOGGER.severe(e.getMessage());
- }
- clientSockets[i] = clientSocket;
- threads[i].start();
- clientSocket = null;
- break;
- }
- }
-
- // setting the clientSocket to null is an indicator the there was
- // room for the
- // connection (i.e. the number of clients < MAX_CLIENTS). If it is
- // not set, then
- // there was no room for the connection, so the client is dropped.
- if (clientSocket != null) {
- try {
- clientSocket.close();
- } catch (IOException e) {
- LOGGER.severe("Error closing (dropped) client socket.");
- LOGGER.severe(e.getMessage());
- }
- LOGGER.warning("Client was dropped. Maximum number of connections reached!");
- }
- }
- }
-
- public void shutdown() {
- try {
- serverSocket.close();
- } catch (IOException e) {
- LOGGER.severe("Error closing server socket.");
- LOGGER.severe(e.getMessage());
- }
-
- try {
- for (int i = 0; i < threads.length; i++) {
- if (threads[i] != null && threads[i].isAlive()) {
- clientSockets[i].close();
- threads[i].interrupt();
- }
- }
- } catch (IOException e) {
- LOGGER.severe("Error closing client socket.");
- LOGGER.severe(e.getMessage());
- }
- }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
index 434f44c..9b29427 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
@@ -14,11 +14,6 @@
*/
package edu.uci.ics.asterix.hyracks.bootstrap;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -26,8 +21,6 @@
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-import edu.uci.ics.asterix.api.aqlj.server.APIClientThreadFactory;
-import edu.uci.ics.asterix.api.aqlj.server.ThreadedServer;
import edu.uci.ics.asterix.api.http.servlet.APIServlet;
import edu.uci.ics.asterix.common.api.AsterixAppContextInfoImpl;
import edu.uci.ics.asterix.common.config.GlobalConfig;
@@ -39,21 +32,17 @@
import edu.uci.ics.hyracks.api.application.ICCBootstrap;
/**
- * The bootstrap class of the application that will manage its
- * life cycle at the Cluster Controller.
+ * The bootstrap class of the application that will manage its life cycle at the
+ * Cluster Controller.
*/
public class CCBootstrapImpl implements ICCBootstrap {
private static final Logger LOGGER = Logger.getLogger(CCBootstrapImpl.class.getName());
private static final int DEFAULT_WEB_SERVER_PORT = 19001;
- public static final int DEFAULT_API_SERVER_PORT = 14600;
- private static final int DEFAULT_API_NODEDATA_SERVER_PORT = 14601;
-
private Server webServer;
private static IAsterixStateProxy proxy;
private ICCApplicationContext appCtx;
- private ThreadedServer apiServer;
@Override
public void start() throws Exception {
@@ -61,23 +50,15 @@
LOGGER.info("Starting Asterix cluster controller");
}
- // Set the AsterixStateProxy to be the distributed object
proxy = AsterixStateProxy.registerRemoteObject();
proxy.setAsterixProperties(AsterixProperties.INSTANCE);
appCtx.setDistributedState(proxy);
- // Create the metadata manager
MetadataManager.INSTANCE = new MetadataManager(proxy);
- // Setup and start the web interface
setupWebServer();
webServer.start();
- // Setup and start the API server
- setupAPIServer();
- apiServer.start();
-
- //Initialize AsterixAppContext
AsterixAppContextInfoImpl.initialize(appCtx);
}
@@ -89,7 +70,6 @@
AsterixStateProxy.unregisterRemoteObject();
webServer.stop();
- apiServer.shutdown();
}
@Override
@@ -110,31 +90,4 @@
webServer.setHandler(context);
context.addServlet(new ServletHolder(new APIServlet()), "/*");
}
-
- private void setupAPIServer() throws Exception {
- // set the APINodeDataServer ports
- int startPort = DEFAULT_API_NODEDATA_SERVER_PORT;
- Map<String, Set<String>> nodeNameMap = new HashMap<String, Set<String>>();
- getIPAddressNodeMap(nodeNameMap);
-
- for (Map.Entry<String, Set<String>> entry : nodeNameMap.entrySet()) {
- Set<String> nodeNames = entry.getValue();
- Iterator<String> it = nodeNames.iterator();
- while (it.hasNext()) {
- AsterixNodeState ns = new AsterixNodeState();
- ns.setAPINodeDataServerPort(startPort++);
- proxy.setAsterixNodeState(it.next(), ns);
- }
- }
- apiServer = new ThreadedServer(DEFAULT_API_SERVER_PORT, new APIClientThreadFactory(appCtx));
- }
-
- private void getIPAddressNodeMap(Map<String, Set<String>> nodeNameMap) throws IOException {
- nodeNameMap.clear();
- try {
- appCtx.getCCContext().getIPAddressNodeMap(nodeNameMap);
- } catch (Exception e) {
- throw new IOException("Unable to obtain IP address node map", e);
- }
- }
}
\ No newline at end of file
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
index b1e7481..185c608 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
@@ -19,8 +19,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import edu.uci.ics.asterix.api.aqlj.server.NodeDataClientThreadFactory;
-import edu.uci.ics.asterix.api.aqlj.server.ThreadedServer;
import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
import edu.uci.ics.asterix.metadata.MetadataManager;
import edu.uci.ics.asterix.metadata.MetadataNode;
@@ -37,7 +35,6 @@
private AsterixAppRuntimeContext runtimeContext;
private String nodeId;
private boolean isMetadataNode = false;
- private ThreadedServer apiNodeDataServer;
@Override
public void start() throws Exception {
@@ -48,10 +45,8 @@
runtimeContext = new AsterixAppRuntimeContext(ncApplicationContext);
runtimeContext.initialize();
-
ncApplicationContext.setApplicationObject(runtimeContext);
- // Initialize metadata if this node is the metadata node
IAsterixStateProxy proxy = (IAsterixStateProxy) ncApplicationContext.getDistributedState();
isMetadataNode = nodeId.equals(proxy.getAsterixProperties().getMetadataNodeName());
if (isMetadataNode) {
@@ -60,20 +55,11 @@
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Bootstrapping metadata");
}
-
MetadataManager.INSTANCE = new MetadataManager(proxy);
MetadataManager.INSTANCE.init();
MetadataBootstrap.startUniverse(proxy.getAsterixProperties(), ncApplicationContext);
-
}
- // Start a sub-component for the API server. This server is only connected to by the
- // API server that lives on the CC and never by a client wishing to execute AQL.
- // TODO: The API sub-system will change dramatically in the future and this code will go away,
- // but leave it for now.
- AsterixNodeState ns = (AsterixNodeState) proxy.getAsterixNodeState(nodeId);
- apiNodeDataServer = new ThreadedServer(ns.getAPINodeDataServerPort(), new NodeDataClientThreadFactory());
- apiNodeDataServer.start();
}
public void registerRemoteMetadataNode(IAsterixStateProxy proxy) throws RemoteException {
@@ -93,12 +79,9 @@
LOGGER.info("Stopping Asterix node controller: " + nodeId);
}
- // Quiesce metadata
if (isMetadataNode) {
MetadataBootstrap.stopUniverse();
}
-
- apiNodeDataServer.shutdown();
runtimeContext.deinitialize();
}
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index 4dfe106..0931994 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -5,27 +5,12 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.charset.Charset;
-import edu.uci.ics.asterix.api.aqlj.client.AQLJClientDriver;
-import edu.uci.ics.asterix.api.aqlj.client.IADMCursor;
-import edu.uci.ics.asterix.api.aqlj.client.IAQLJConnection;
-import edu.uci.ics.asterix.api.aqlj.client.IAQLJResult;
-import edu.uci.ics.asterix.api.aqlj.common.AQLJException;
import edu.uci.ics.asterix.api.java.AsterixJavaClient;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.base.IAObject;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
public class TestsUtils {
@@ -98,112 +83,6 @@
}
- public static void runScriptAndCompareWithResultViaClientAPI(File scriptFile, PrintWriter print, File expectedFile,
- File actualFile, int apiPort) throws Exception {
- FileOutputStream fos = new FileOutputStream(actualFile);
- String query = queryFromFile(scriptFile);
- IAQLJConnection conn = null;
- IAQLJResult res = null;
- try {
- conn = AQLJClientDriver.getConnection("localhost", apiPort, "Metadata");
- res = conn.execute(query);
-
- while (res.next()) {
- leafPrint(conn, res, fos);
- }
- } catch (AQLJException e) {
- e.printStackTrace();
- } finally {
- // be sure that we close the connection and the result cursor
- if (res != null) {
- res.close();
- }
- if (conn != null) {
- conn.close();
- }
- }
- fos.close();
-
- BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
- "UTF-8"));
- BufferedReader readerActual = new BufferedReader(
- new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
- String lineExpected, lineActual;
- int num = 1;
- try {
- while ((lineExpected = readerExpected.readLine()) != null) {
- lineActual = readerActual.readLine();
- // Assert.assertEquals(lineExpected, lineActual);
- if (lineActual == null) {
- throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< " + lineExpected
- + "\n> ");
- }
- if (!equalStrings(lineExpected, lineActual)) {
- throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< " + lineExpected
- + "\n> " + lineActual);
- }
- ++num;
- }
- lineActual = readerActual.readLine();
- // Assert.assertEquals(null, lineActual);
- if (lineActual != null) {
- throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< \n> " + lineActual);
- }
- actualFile.delete();
- } finally {
- readerExpected.close();
- readerActual.close();
- }
-
- }
-
- public static void leafPrint(IAQLJConnection conn, IADMCursor c, FileOutputStream fos) throws AQLJException,
- UnsupportedEncodingException, IOException {
- IAType t;
- IAObject o;
- String fieldNames[];
- IADMCursor cur;
-
- o = c.get();
- if (o == null) {
- return;
- }
-
- t = o.getType();
- if (t instanceof AbstractCollectionType) {
- fos.write("AbstractCollectionType: \n".getBytes("UTF-8"));
- cur = conn.createADMCursor();
- c.position(cur);
- while (cur.next()) {
-
- leafPrint(conn, cur, fos);
- }
- } else if (t instanceof ARecordType) {
- fos.write("ARecordType: \n".getBytes("UTF-8"));
- fieldNames = ((ARecordType) t).getFieldNames();
- for (int i = 0; i < fieldNames.length; i++) {
- cur = conn.createADMCursor();
- c.position(cur, fieldNames[i]);
- fos.write(("field: " + fieldNames[i] + "\n").getBytes("UTF-8"));
- leafPrint(conn, cur, fos);
- }
- } else {
- fos.write((o.toString() + "\n").getBytes("UTF-8"));
- }
- }
-
- private static String queryFromFile(File f) throws IOException {
- FileInputStream fis = new FileInputStream(f);
- try {
- FileChannel fc = fis.getChannel();
- MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
- return Charset.forName("UTF-8").decode(bb).toString();
- } finally {
- fis.close();
- }
-
- }
-
private static boolean equalStrings(String s1, String s2) {
String[] rowsOne = s1.split("\n");
String[] rowsTwo = s2.split("\n");
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
deleted file mode 100644
index 0301675..0000000
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package edu.uci.ics.asterix.test.aqlj;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import org.junit.AfterClass;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.internal.AssumptionViolatedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import edu.uci.ics.asterix.api.common.AsterixHyracksIntegrationUtil;
-import edu.uci.ics.asterix.common.config.GlobalConfig;
-import edu.uci.ics.asterix.hyracks.bootstrap.CCBootstrapImpl;
-import edu.uci.ics.asterix.test.aql.TestsUtils;
-import edu.uci.ics.asterix.test.common.TestHelper;
-
-@RunWith(Parameterized.class)
-public class ClientAPITest {
- private static final PrintWriter ERR = new PrintWriter(System.err);
- private static final String EXTENSION_QUERY = "aql";
- private static final String FILENAME_IGNORE = "ignore.txt";
- private static final String FILENAME_ONLY = "only.txt";
- private static final ArrayList<String> ignore = readFile(FILENAME_IGNORE);
- private static final ArrayList<String> only = readFile(FILENAME_ONLY);
- private static final String PATH_ACTUAL = "aqljtest/";
- private static final String PATH_BASE = "src/test/resources/aqljts/";
- private static final String PATH_EXPECTED = PATH_BASE + "results/";
- private static final String PATH_QUERIES = PATH_BASE + "queries/";
- private static final String SEPARATOR = System.getProperty("file.separator");
-
- private static final String TEST_CONFIG_FILE_NAME = "test.properties";
- private static final String[] ASTERIX_DATA_DIRS = new String[] { "nc1data", "nc2data" };
-
- private static final Logger LOGGER = Logger.getLogger(ClientAPITest.class.getName());
-
- private static ArrayList<String> readFile(String fileName) {
- ArrayList<String> list = new ArrayList<String>();
- BufferedReader result;
- try {
- result = new BufferedReader(new InputStreamReader(new FileInputStream(PATH_BASE + fileName), "UTF-8"));
- while (true) {
- String line = result.readLine();
- if (line == null) {
- break;
- } else {
- String s = line.trim();
- if (s.length() > 0) {
- list.add(s);
- }
- }
- }
- result.close();
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- }
- return list;
- }
-
- @BeforeClass
- public static void setUp() throws Exception {
- System.setProperty(GlobalConfig.CONFIG_FILE_PROPERTY, TEST_CONFIG_FILE_NAME);
- System.setProperty(GlobalConfig.WEB_SERVER_PORT_PROPERTY, "19002");
- File outdir = new File(PATH_ACTUAL);
- outdir.mkdirs();
- AsterixHyracksIntegrationUtil.init();
- // _bootstrap.start();
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- // _bootstrap.stop();
- AsterixHyracksIntegrationUtil.deinit();
- File outdir = new File(PATH_ACTUAL);
- File[] files = outdir.listFiles();
- if (files == null || files.length == 0) {
- outdir.delete();
- }
- // clean up the files written by the ASTERIX storage manager
- for (String d : ASTERIX_DATA_DIRS) {
- TestsUtils.deleteRec(new File(d));
- }
- }
-
- private static void suiteBuild(File dir, Collection<Object[]> testArgs, String path) {
- for (File file : dir.listFiles()) {
- if (file.isDirectory() && !file.getName().startsWith(".")) {
- suiteBuild(file, testArgs, path + file.getName() + SEPARATOR);
- }
- if (file.isFile() && file.getName().endsWith(EXTENSION_QUERY)
- // && !ignore.contains(path + file.getName())
- ) {
- String resultFileName = TestsUtils.aqlExtToResExt(file.getName());
- File expectedFile = new File(PATH_EXPECTED + path + resultFileName);
- File actualFile = new File(PATH_ACTUAL + SEPARATOR + path.replace(SEPARATOR, "_") + resultFileName);
- testArgs.add(new Object[] { file, expectedFile, actualFile });
- }
- }
- }
-
- @Parameters
- public static Collection<Object[]> tests() {
- Collection<Object[]> testArgs = new ArrayList<Object[]>();
- suiteBuild(new File(PATH_QUERIES), testArgs, "");
- return testArgs;
- }
-
- private File actualFile;
- private File expectedFile;
- private File queryFile;
-
- public ClientAPITest(File queryFile, File expectedFile, File actualFile) {
- this.queryFile = queryFile;
- this.expectedFile = expectedFile;
- this.actualFile = actualFile;
- }
-
- @Test
- public void test() throws Exception {
- try {
- String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length())
- .replace(SEPARATOR.charAt(0), '/');
-
- if (!only.isEmpty()) {
- Assume.assumeTrue(TestHelper.isInPrefixList(only, queryFileShort));
- }
- Assume.assumeTrue(!TestHelper.isInPrefixList(ignore, queryFileShort));
- LOGGER.severe("RUNNING TEST: " + queryFile + " \n");
- TestsUtils.runScriptAndCompareWithResultViaClientAPI(queryFile, ERR, expectedFile, actualFile,
- CCBootstrapImpl.DEFAULT_API_SERVER_PORT);
- } catch (Exception e) {
- if (!(e instanceof AssumptionViolatedException)) {
- LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
- throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
- } else {
- throw e;
- }
- }
- }
-}
diff --git a/asterix-app/src/test/resources/aqljts/ignore.txt b/asterix-app/src/test/resources/aqljts/ignore.txt
deleted file mode 100644
index e69de29..0000000
--- a/asterix-app/src/test/resources/aqljts/ignore.txt
+++ /dev/null
diff --git a/asterix-app/src/test/resources/aqljts/only.txt b/asterix-app/src/test/resources/aqljts/only.txt
deleted file mode 100644
index e69de29..0000000
--- a/asterix-app/src/test/resources/aqljts/only.txt
+++ /dev/null
diff --git a/asterix-app/src/test/resources/aqljts/queries/gram-tokens_01.aql b/asterix-app/src/test/resources/aqljts/queries/gram-tokens_01.aql
deleted file mode 100644
index 5f2b961..0000000
--- a/asterix-app/src/test/resources/aqljts/queries/gram-tokens_01.aql
+++ /dev/null
@@ -1,4 +0,0 @@
-let $txt := "Jürgen S. Generic's Car"
-let $tokens := gram-tokens($txt, 3, false)
-for $token in $tokens
-return $token
diff --git a/asterix-app/src/test/resources/aqljts/queries/nested_01.aql b/asterix-app/src/test/resources/aqljts/queries/nested_01.aql
deleted file mode 100644
index 968f314..0000000
--- a/asterix-app/src/test/resources/aqljts/queries/nested_01.aql
+++ /dev/null
@@ -1,9 +0,0 @@
-for $x in [1]
-return {"x":
- [{"r": [["a", "b", "c"], ["d", "e", "f"]]}],
- "y":
- [{"s": [[1, 2, 3], [4, 5, 6]]}],
- "z":
- [{"t": [datetime("2011-09-16T11:00:00Z")]}]
- }
-
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/aqljts/results/gram-tokens_01.adm b/asterix-app/src/test/resources/aqljts/results/gram-tokens_01.adm
deleted file mode 100644
index f0f59c3..0000000
--- a/asterix-app/src/test/resources/aqljts/results/gram-tokens_01.adm
+++ /dev/null
@@ -1,21 +0,0 @@
-AString: {jür}
-AString: {ürg}
-AString: {rge}
-AString: {gen}
-AString: {en }
-AString: {n s}
-AString: { s.}
-AString: {s. }
-AString: {. g}
-AString: { ge}
-AString: {gen}
-AString: {ene}
-AString: {ner}
-AString: {eri}
-AString: {ric}
-AString: {ic'}
-AString: {c's}
-AString: {'s }
-AString: {s c}
-AString: { ca}
-AString: {car}
diff --git a/asterix-app/src/test/resources/aqljts/results/nested_01.adm b/asterix-app/src/test/resources/aqljts/results/nested_01.adm
deleted file mode 100644
index 27de5c0..0000000
--- a/asterix-app/src/test/resources/aqljts/results/nested_01.adm
+++ /dev/null
@@ -1,33 +0,0 @@
-ARecordType:
-field: x
-AbstractCollectionType:
-ARecordType:
-field: r
-AbstractCollectionType:
-AbstractCollectionType:
-AString: {a}
-AString: {b}
-AString: {c}
-AbstractCollectionType:
-AString: {d}
-AString: {e}
-AString: {f}
-field: y
-AbstractCollectionType:
-ARecordType:
-field: s
-AbstractCollectionType:
-AbstractCollectionType:
-AInt32: {1}
-AInt32: {2}
-AInt32: {3}
-AbstractCollectionType:
-AInt32: {4}
-AInt32: {5}
-AInt32: {6}
-field: z
-AbstractCollectionType:
-ARecordType:
-field: t
-AbstractCollectionType:
-ADateTime: { 2011-09-16T11:00:00.000Z }
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IAsterixStateProxy.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IAsterixStateProxy.java
index 2b915d9..5f772c7 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IAsterixStateProxy.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IAsterixStateProxy.java
@@ -32,8 +32,4 @@
public IMetadataNode getMetadataNode() throws RemoteException;
public AsterixProperties getAsterixProperties() throws RemoteException;
-
- public Object getAsterixNodeState(String nodeName) throws RemoteException;
-
- public void setAsterixNodeState(String nodeName, Object ns) throws RemoteException;
}
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
index e2c02fa..3946fa6 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
@@ -17,7 +17,6 @@
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
-import java.util.HashMap;
import java.util.logging.Logger;
import edu.uci.ics.asterix.metadata.api.IAsterixStateProxy;
@@ -33,7 +32,6 @@
private IMetadataNode metadataNode;
private AsterixProperties asterixProperties;
private static final IAsterixStateProxy cc = new AsterixStateProxy();
- private final HashMap<String, Object> nodeStateMap = new HashMap<String, Object>();
public static IAsterixStateProxy registerRemoteObject() throws RemoteException {
IAsterixStateProxy stub = (IAsterixStateProxy) UnicastRemoteObject.exportObject(cc, 0);
@@ -65,14 +63,4 @@
public AsterixProperties getAsterixProperties() throws RemoteException {
return this.asterixProperties;
}
-
- @Override
- synchronized public Object getAsterixNodeState(String nodeName) throws RemoteException {
- return nodeStateMap.get(nodeName);
- }
-
- @Override
- synchronized public void setAsterixNodeState(String nodeName, Object ns) throws RemoteException {
- nodeStateMap.put(nodeName, ns);
- }
}