Removal of mongo-emulator along with associated dependencies
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/5f552e7e Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5f552e7e Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5f552e7e Branch: refs/heads/USERGRID-1246-MASTER Commit: 5f552e7ec838ce30412f1edd482b725e78b991c8 Parents: 6df86b4 Author: George Reyes <g...@apache.org> Authored: Thu Apr 28 14:49:55 2016 -0700 Committer: George Reyes <g...@apache.org> Committed: Mon May 2 10:49:34 2016 -0700 ---------------------------------------------------------------------- stack/mongo-emulator/README.txt | 72 --- stack/mongo-emulator/pom.xml | 172 ------ .../src/main/java/META-INF/MANIFEST.MF | 3 - .../usergrid/mongo/MongoChannelHandler.java | 145 ------ .../usergrid/mongo/MongoMessageDecoder.java | 116 ----- .../usergrid/mongo/MongoMessageEncoder.java | 47 -- .../org/apache/usergrid/mongo/MongoQuery.java | 31 -- .../org/apache/usergrid/mongo/MongoServer.java | 172 ------ .../mongo/MongoServerPipelineFactory.java | 56 -- .../usergrid/mongo/commands/Buildinfo.java | 44 -- .../usergrid/mongo/commands/Collstats.java | 59 --- .../apache/usergrid/mongo/commands/Count.java | 67 --- .../apache/usergrid/mongo/commands/Dbstats.java | 41 -- .../usergrid/mongo/commands/Getlasterror.java | 49 -- .../usergrid/mongo/commands/ListDatabases.java | 52 -- .../usergrid/mongo/commands/MongoCommand.java | 82 --- .../mongo/commands/ReplSetGetStatus.java | 38 -- .../usergrid/mongo/commands/ServerStatus.java | 63 --- .../usergrid/mongo/commands/Whatsmyuri.java | 42 -- .../apache/usergrid/mongo/protocol/Message.java | 192 ------- .../apache/usergrid/mongo/protocol/OpCrud.java | 47 -- .../usergrid/mongo/protocol/OpDelete.java | 197 ------- .../usergrid/mongo/protocol/OpGetMore.java | 113 ---- .../usergrid/mongo/protocol/OpInsert.java | 181 ------- .../usergrid/mongo/protocol/OpKillCursors.java | 116 ----- .../apache/usergrid/mongo/protocol/OpMsg.java | 78 --- .../apache/usergrid/mongo/protocol/OpQuery.java | 451 ---------------- .../apache/usergrid/mongo/protocol/OpReply.java | 190 ------- .../usergrid/mongo/protocol/OpUpdate.java | 207 -------- .../usergrid/mongo/query/MongoQueryParser.java | 292 ----------- .../mongo/testproxy/MongoMessageFrame.java | 56 -- .../testproxy/MongoProxyInboundHandler.java | 198 ------- .../testproxy/MongoProxyPipelineFactory.java | 54 -- .../mongo/testproxy/MongoProxyServer.java | 56 -- .../testproxy/MongoProxyServerHandler.java | 59 --- .../apache/usergrid/mongo/utils/BSONUtils.java | 51 -- .../usergrid/mongo/AbstractMongoTest.java | 63 --- .../apache/usergrid/mongo/BasicMongoTest.java | 356 ------------- .../usergrid/mongo/DatabaseInitializer.java | 146 ------ .../apache/usergrid/mongo/MongoQueryTest.java | 519 ------------------- .../test/resources/usergrid-test-context.xml | 48 -- 41 files changed, 5021 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/README.txt ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/README.txt b/stack/mongo-emulator/README.txt deleted file mode 100644 index e94394e..0000000 --- a/stack/mongo-emulator/README.txt +++ /dev/null @@ -1,72 +0,0 @@ -Experimental and incomplete implementation of Mongo emulation layer so Mongo -clients can connect to Usergrid. - -There are a number of drivers and tools for talking to MongoDB, which has a -data model that is very similar to that of Usergrid. In order to make it -easier for people to get started quickly with Usergrid, it's desirable for -them to be able to integrate it very quickly into their existing applications. -The goal here is to support the Mongo native wire protocol and to map enough -of the query and CRUD operations so that this can happen. - -While Mongo is a full-featured database, in practice only a small subset of -it's commands are used. To verify this, a Mongo proxy was written at: - -org.apache.usergrid.mongo.testproxy.MongoProxyServer - -This proxy serves as a "man in the middle" and decodes and logs all Mongo -commands sent to and from an application and MongoDB. Using a couple of GUI -tools as well as the Mongo command-line client, we were able to see that only -a handful of commands are commonly used for listing databases, collections, -and for querying content. - -Mongo uses a wire protocol described here: - -http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol - -Mongo uses BSON, which is a binary JSON format, as part of the wire protocol. -For compatibility, we're using the BSON encoder from the Mongo Java driver: - -https://github.com/mongodb/mongo-java-driver/ - -However, since we're using Jackson as our JSON library for the rest of -Usergrid, the idea is to switch over to Bson4Jackson: - -https://github.com/michel-kraemer/bson4jackson - -The commands Mongo supports are listed here: - -http://www.mongodb.org/display/DOCS/List+of+Database+Commands - -Mongo's system metadata is listed here: - -http://www.mongodb.org/display/DOCS/Mongo+Metadata - -Queries are described here: - -http://www.mongodb.org/display/DOCS/Mongo+Query+Language - - -Mapping Usergrid Multi-tenancy to Mongo Security - -First steps are to simply be able to handle a client login and map it to a -Usergrid account. - -Authentication is described here: - -http://www.mongodb.org/display/DOCS/Security+and+Authentication -http://www.mongodb.org/display/DOCS/Implementing+Authentication+in+a+Driver - -A user who authenticates against the Mongo 'admin' account will be actually -logging in as a Usergrid admin user who is a member of one or more Usergrid -accounts, each of which contains a set of applications that user is able to -administer. While they list the databases via the Mongo API, what they will -be seeing is the aggregate list of the applications for all the accounts they -are members of. - -For any database (Usergrid application), they'll be able to list the collections. - -Note: Internally, Mongo refers to it's collections as "namespaces", which -is a potential point of confusion between previous versions of Usergrid which -used the term "namespace" to describe applications. - - http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/pom.xml ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/pom.xml b/stack/mongo-emulator/pom.xml deleted file mode 100644 index 6d4e9ac..0000000 --- a/stack/mongo-emulator/pom.xml +++ /dev/null @@ -1,172 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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 at - - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid</artifactId> - <version>2.0.0-SNAPSHOT</version> - <relativePath>../</relativePath> - </parent> - - <artifactId>usergrid-mongo-emulator</artifactId> - <name>Usergrid MongoDB Emulator</name> - <description>Mongo emulation layer for Usergrid system.</description> - <packaging>jar</packaging> - - <reporting> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.7</version> - </plugin> - </plugins> - </reporting> - - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - <includes> - <include>**/*.xml</include> - </includes> - </resource> - </resources> - - <testResources> - <testResource> - <directory>src/test/resources</directory> - <filtering>true</filtering> - <includes> - <include>**/*.xml</include> - </includes> - </testResource> - </testResources> - - </build> - - <dependencies> - - <!-- Usergrid Dependencies --> - - <dependency> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid-config</artifactId> - <version>${project.version}</version> - <scope>runtime</scope> - </dependency> - - <dependency> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid-core</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid-services</artifactId> - <version>${project.version}</version> - </dependency> - - <!-- Apache Dependencies --> - - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - - <!-- SUN, Javax Package and Other Com Dependencies --> - - <!-- --> - - <!-- Codehaus, Spring and Other Org Dependencies --> - - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - </dependency> - - <dependency> - <groupId>de.undercouch</groupId> - <artifactId>bson4jackson</artifactId> - </dependency> - - <dependency> - <!-- TODO - should not scope be 'test' ? --> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - - <!-- Testing and Logging Dependencies --> - - <dependency> - <groupId>org.hectorclient</groupId> - <artifactId>hector-test</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid-config</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <classifier>tests</classifier> - </dependency> - - <dependency> - <groupId>org.apache.usergrid</groupId> - <artifactId>usergrid-core</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <classifier>tests</classifier> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jul-to-slf4j</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/META-INF/MANIFEST.MF b/stack/mongo-emulator/src/main/java/META-INF/MANIFEST.MF deleted file mode 100644 index 5e94951..0000000 --- a/stack/mongo-emulator/src/main/java/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoChannelHandler.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoChannelHandler.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoChannelHandler.java deleted file mode 100644 index 90a2f47..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoChannelHandler.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.management.ManagementService; -import org.apache.usergrid.mongo.protocol.Message; -import org.apache.usergrid.mongo.protocol.OpCrud; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.services.ServiceManagerFactory; - -import org.apache.shiro.mgt.SessionsSecurityManager; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.subject.support.SubjectThreadState; -import org.apache.shiro.util.ThreadState; - - -public class MongoChannelHandler extends SimpleChannelUpstreamHandler { - - private static final Logger logger = LoggerFactory.getLogger( MongoChannelHandler.class ); - - private final EntityManagerFactory emf; - private final ServiceManagerFactory smf; - private final ManagementService management; - private final SessionsSecurityManager securityManager; - - Subject subject = null; - - - public MongoChannelHandler( EntityManagerFactory emf, ServiceManagerFactory smf, ManagementService management, - SessionsSecurityManager securityManager ) { - super(); - - logger.info( "Starting new client connection..." ); - this.emf = emf; - this.smf = smf; - this.management = management; - this.securityManager = securityManager; - - if ( securityManager != null ) { - subject = new Subject.Builder( securityManager ).buildSubject(); - } - } - - - public EntityManagerFactory getEmf() { - return emf; - } - - - public ServiceManagerFactory getSmf() { - return smf; - } - - - public ManagementService getOrganizations() { - return management; - } - - - public SessionsSecurityManager getSecurityManager() { - return securityManager; - } - - - @Override - public void messageReceived( ChannelHandlerContext ctx, MessageEvent e ) { - - ThreadState threadState = null; - if ( subject != null ) { - threadState = new SubjectThreadState( subject ); - threadState.bind(); - // logger.info("Security subject bound to thread"); - } - - try { - - Message message = null; - if ( e.getMessage() instanceof Message ) { - message = ( Message ) e.getMessage(); - } - - if ( message != null ) { - logger.info( ">>> {}\n", message ); - OpReply reply = handleMessage( ctx, e, message ); - logger.info( "<<< {}\n", reply ); - - if ( reply != null ) { - e.getChannel().write( reply ); - } - } - } - //an error occurred. Set this as the attachment so subsequent calls to getlastError can return correct - //errors - catch ( Exception ex ) { - ctx.setAttachment( ex ); - } - - finally { - if ( threadState != null ) { - threadState.clear(); - // logger.info("Security subject unbound from thread"); - } - } - } - - - @Override - public void exceptionCaught( ChannelHandlerContext ctx, ExceptionEvent e ) { - logger.warn( "Unexpected exception from downstream.", e.getCause() ); - e.getChannel().close(); - } - - - public OpReply handleMessage( ChannelHandlerContext ctx, MessageEvent e, Message message ) { - logger.debug( "message type: {}", message.getClass().getCanonicalName() ); - if ( message instanceof OpCrud ) { - return ( ( OpCrud ) message ).doOp( this, ctx, e ); - } - - OpReply reply = new OpReply( message ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageDecoder.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageDecoder.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageDecoder.java deleted file mode 100644 index 4252276..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageDecoder.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.mongo.protocol.Message; -import org.apache.usergrid.mongo.protocol.OpDelete; -import org.apache.usergrid.mongo.protocol.OpGetMore; -import org.apache.usergrid.mongo.protocol.OpInsert; -import org.apache.usergrid.mongo.protocol.OpKillCursors; -import org.apache.usergrid.mongo.protocol.OpMsg; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.mongo.protocol.OpUpdate; - - -public class MongoMessageDecoder extends FrameDecoder { - - private static final Logger logger = LoggerFactory.getLogger( MongoMessageDecoder.class ); - - - @Override - protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf ) throws Exception { - - if ( buf.readableBytes() < 4 ) { - logger.info( "Needed at least 4 bytes, only " + buf.readableBytes() + " available" ); - return null; - } - - // logger.info("Mongo message decoding..."); - - int length = buf.getInt( buf.readerIndex() ); - - if ( length < 0 ) { - logger.info( "Negative length " + length ); - return null; - } - - if ( buf.readableBytes() < length ) { - logger.info( "Needed " + length + " bytes, only " + buf.readableBytes() + " available" ); - return null; - } - - // logger.info("Attempting to read " + length + " bytes"); - ChannelBuffer frame = buf.readSlice( length ); - - int opCode = frame.getInt( frame.readerIndex() + 12 ); - - // logger.info("Mongo message opcode " + opCode + " received"); - - Message message = null; - if ( opCode == Message.OP_DELETE ) { - message = new OpDelete(); - } - else if ( opCode == Message.OP_GET_MORE ) { - message = new OpGetMore(); - } - else if ( opCode == Message.OP_INSERT ) { - message = new OpInsert(); - } - else if ( opCode == Message.OP_KILL_CURSORS ) { - message = new OpKillCursors(); - } - else if ( opCode == Message.OP_MSG ) { - message = new OpMsg(); - } - else if ( opCode == Message.OP_QUERY ) { - message = new OpQuery(); - } - else if ( opCode == Message.OP_REPLY ) { - message = new OpReply(); - } - else if ( opCode == Message.OP_UPDATE ) { - message = new OpUpdate(); - } - - if ( message != null ) { - message.decode( frame ); - } - else { - logger.info( "Mongo unrecongnized message opcode " + opCode + " received" ); - } - - // logger.info(message); - - return message; - } - - - static MongoMessageDecoder _instance = new MongoMessageDecoder(); - - - public static Message decode( ChannelBuffer buf ) throws Exception { - return ( Message ) _instance.decode( null, null, buf.duplicate() ); - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageEncoder.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageEncoder.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageEncoder.java deleted file mode 100644 index 0d4d167..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoMessageEncoder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.mongo.protocol.Message; - - -public class MongoMessageEncoder extends SimpleChannelHandler { - - @SuppressWarnings("unused") - private static final Logger logger = LoggerFactory.getLogger( MongoMessageEncoder.class ); - - - @Override - public void writeRequested( ChannelHandlerContext ctx, MessageEvent e ) { - - // logger.info("Mongo message encoding..."); - - Message message = ( Message ) e.getMessage(); - - ChannelBuffer buf = message.encode( null ); - - Channels.write( ctx, e.getFuture(), buf ); - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoQuery.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoQuery.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoQuery.java deleted file mode 100644 index bbc13b4..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoQuery.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import org.bson.BSONObject; - - -public class MongoQuery { - - BSONObject query; - - - public MongoQuery( BSONObject query ) { - this.query = query; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServer.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServer.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServer.java deleted file mode 100644 index 5660dfa..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServer.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import java.net.InetSocketAddress; -import java.nio.ByteOrder; -import java.util.Properties; -import java.util.concurrent.Executors; - -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.buffer.HeapChannelBufferFactory; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.jboss.netty.handler.execution.ExecutionHandler; -import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.apache.usergrid.management.ManagementService; -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImpl; -import org.apache.usergrid.services.ServiceManagerFactory; - -import org.apache.shiro.mgt.DefaultSecurityManager; -import org.apache.shiro.mgt.SessionsSecurityManager; -import org.apache.shiro.realm.Realm; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - - -public class MongoServer { - - private static final Logger logger = LoggerFactory.getLogger( MongoServer.class ); - - EntityManagerFactory emf; - ServiceManagerFactory smf; - ManagementService management; - Realm realm; - SessionsSecurityManager securityManager; - Channel channel; - Properties properties; - - - public static void main( String[] args ) throws Exception { - MongoServer server = new MongoServer(); - server.startSpring(); - server.startServer(); - } - - - public MongoServer() { - } - - - @Autowired - public void setEntityManagerFactory( EntityManagerFactory emf ) { - this.emf = emf; - } - - - @Autowired - public void setServiceManagerFactory( ServiceManagerFactory smf ) { - this.smf = smf; - } - - - @Autowired - public void setManagementService( ManagementService management ) { - this.management = management; - } - - - @Autowired - public void setRealm( Realm realm ) { - this.realm = realm; - } - - - public Properties getProperties() { - return properties; - } - - - @Autowired - public void setProperties( Properties properties ) { - this.properties = properties; - } - - - public String[] getApplicationContextLocations() { - String[] locations = { "applicationContext.xml" }; - return locations; - } - - - public void startSpring() { - - String[] locations = getApplicationContextLocations(); - ApplicationContext ac = new ClassPathXmlApplicationContext( locations ); - - AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); - acbf.autowireBeanProperties( this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false ); - acbf.initializeBean( this, "mongoServer" ); - - assertNotNull( emf ); - assertTrue( "EntityManagerFactory is instance of EntityManagerFactoryImpl", - emf instanceof EntityManagerFactoryImpl ); - } - - - public void startServer() { - - if ( ( properties != null ) && ( Boolean - .parseBoolean( properties.getProperty( "usergrid.mongo.disable", "false" ) ) ) ) { - logger.info( "Usergrid Mongo Emulation Server Disabled" ); - return; - } - - logger.info( "Starting Usergrid Mongo Emulation Server" ); - - if ( realm != null ) { - securityManager = new DefaultSecurityManager( realm ); - } - - // Configure the server. - ServerBootstrap bootstrap = new ServerBootstrap( - new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool() ) ); - - bootstrap.setOption( "child.bufferFactory", HeapChannelBufferFactory.getInstance( ByteOrder.LITTLE_ENDIAN ) ); - - // Set up the pipeline factory. - ExecutionHandler executionHandler = - new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) ); - // TODO if config'ed for SSL, start the SslMSPF instead, change port as well? - bootstrap.setPipelineFactory( - new MongoServerPipelineFactory( emf, smf, management, securityManager, executionHandler ) ); - - // Bind and start to accept incoming connections. - channel = bootstrap.bind( new InetSocketAddress( 27017 ) ); - - logger.info( "Usergrid Mongo API Emulation Server accepting connections..." ); - } - - - public void stopServer() { - logger.info( "Stopping Usergrid Mongo Emulation Server" ); - if ( channel != null ) { - channel.close(); - channel = null; - } - logger.info( "Usergrid Mongo API Emulation Server stopped..." ); - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServerPipelineFactory.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServerPipelineFactory.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServerPipelineFactory.java deleted file mode 100644 index 9bd78ac..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/MongoServerPipelineFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo; - - -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.handler.execution.ExecutionHandler; -import org.apache.usergrid.management.ManagementService; -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.services.ServiceManagerFactory; - -import org.apache.shiro.mgt.SessionsSecurityManager; - - -public class MongoServerPipelineFactory implements ChannelPipelineFactory { - - private final ExecutionHandler executionHandler; - private final EntityManagerFactory emf; - private final ServiceManagerFactory smf; - private final ManagementService management; - private final SessionsSecurityManager securityManager; - - - public MongoServerPipelineFactory( EntityManagerFactory emf, ServiceManagerFactory smf, - ManagementService management, SessionsSecurityManager securityManager, - ExecutionHandler executionHandler ) { - this.emf = emf; - this.smf = smf; - this.management = management; - this.securityManager = securityManager; - this.executionHandler = executionHandler; - } - - - @Override - public ChannelPipeline getPipeline() throws Exception { - return Channels.pipeline( new MongoMessageEncoder(), new MongoMessageDecoder(), executionHandler, - new MongoChannelHandler( emf, smf, management, securityManager ) ); - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Buildinfo.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Buildinfo.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Buildinfo.java deleted file mode 100644 index 33d3153..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Buildinfo.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Buildinfo extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - OpReply reply = new OpReply( opQuery ); - reply.addDocument( - map( entry( "version", "1.8.1" ), entry( "gitVersion", "a429cd4f535b2499cc4130b06ff7c26f41c00f04" ), - entry( "sysInfo", - "Darwin erh2.10gen.cc 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST " - + "2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40" ), - entry( "bits", 64 ), entry( "debug", false ), entry( "maxBsonObjectSize", 16777216 ), - entry( "ok", 1.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java deleted file mode 100644 index 02a0e9a..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.management.ApplicationInfo; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.persistence.EntityManager; -import org.apache.usergrid.persistence.index.query.Identifier; -import org.apache.usergrid.security.shiro.utils.SubjectUtils; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Collstats extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - ApplicationInfo application = SubjectUtils.getApplication( Identifier.from( opQuery.getDatabaseName() ) ); - OpReply reply = new OpReply( opQuery ); - if ( application == null ) { - return reply; - } - EntityManager em = handler.getEmf().getEntityManager( application.getId() ); - String collectionName = ( String ) opQuery.getQuery().get( "collstats" ); - long count = 0; - try { - count = em.getApplicationCollectionSize( collectionName ); - } - catch ( Exception e1 ) { - } - reply.addDocument( - map( entry( "ns", opQuery.getDatabaseName() + "." + collectionName ), entry( "count", count ), - entry( "size", count * 40 ), entry( "avgObjSize", 40.0 ), entry( "storageSize", 8192 ), - entry( "numExtents", 1 ), entry( "nindexes", 1 ), entry( "lastExtentSize", 8192 ), - entry( "paddingFactor", 1.0 ), entry( "flags", 1 ), entry( "totalIndexSize", 8192 ), - entry( "indexSizes", map( "_id_", 8192 ) ), entry( "ok", 1.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java deleted file mode 100644 index bac3e4f..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.management.ApplicationInfo; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.persistence.EntityManager; -import org.apache.usergrid.persistence.Results; -import org.apache.usergrid.persistence.index.query.Identifier; -import org.apache.usergrid.persistence.index.query.Query.Level; -import org.apache.usergrid.security.shiro.utils.SubjectUtils; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Count extends MongoCommand { - - private static final Logger logger = LoggerFactory.getLogger( Count.class ); - - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - - OpReply reply = new OpReply( opQuery ); - - ApplicationInfo application = SubjectUtils.getApplication( Identifier.from( opQuery.getDatabaseName() ) ); - - if ( application == null ) { - return reply; - } - - EntityManager em = handler.getEmf().getEntityManager( application.getId() ); - - try { - Results results = - em.getCollection( em.getApplicationRef(), ( String ) opQuery.getQuery().get( "count" ), null, - 100000, Level.IDS, false ); - reply.addDocument( map( entry( "n", results.size() * 1.0 ), entry( "ok", 1.0 ) ) ); - } - catch ( Exception ex ) { - logger.error( "Unable to retrieve collections", ex ); - } - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Dbstats.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Dbstats.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Dbstats.java deleted file mode 100644 index f3ce627..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Dbstats.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Dbstats extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - OpReply reply = new OpReply( opQuery ); - reply.addDocument( map( entry( "db", "local" ), entry( "collections", 3 ), entry( "objects", 4 ), - entry( "avgObjSize", 53.0 ), entry( "dataSize", 212 ), entry( "storageSize", 16640 ), - entry( "numExtents", 3 ), entry( "indexes", 1 ), entry( "indexSize", 8192 ), - entry( "fileSize", 201326592 ), entry( "ok", 1.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Getlasterror.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Getlasterror.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Getlasterror.java deleted file mode 100644 index fc2c161..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Getlasterror.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Getlasterror extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - OpReply reply = new OpReply( opQuery ); - - // there's an error in the attachment - if ( ctx.getAttachment() instanceof Exception ) { - reply.addDocument( map( entry( "n", 0 ), entry( "connectionId", 20 ), entry( "wtime", 0 ), - entry( "err", ( ( Exception ) ctx.getAttachment() ).getMessage() ), entry( "ok", 0.0 ) ) ); - } - else { - reply.addDocument( - map( entry( "n", 0 ), entry( "connectionId", 20 ), entry( "wtime", 0 ), entry( "err", null ), - entry( "ok", 1.0 ) ) ); - } - - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ListDatabases.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ListDatabases.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ListDatabases.java deleted file mode 100644 index 4548dcb..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ListDatabases.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.security.shiro.utils.SubjectUtils; - -import static org.apache.usergrid.utils.MapUtils.map; - - -public class ListDatabases extends MongoCommand { - - final static double DEFAULT_SIZE = 1024 * 1024 * 1024.0; - - - @SuppressWarnings("unchecked") - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - Set<String> applications = SubjectUtils.getApplications().inverse().keySet(); - List<Map<String, Object>> dbs = new ArrayList<Map<String, Object>>(); - for ( String ns : applications ) { - dbs.add( ( Map<String, Object> ) map( "name", ns, "sizeOnDisk", DEFAULT_SIZE, "empty", false ) ); - } - OpReply reply = new OpReply( opQuery ); - reply.addDocument( map( "databases", dbs, "totalSize", 1.0, "ok", 1.0 ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/MongoCommand.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/MongoCommand.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/MongoCommand.java deleted file mode 100644 index 224de0e..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/MongoCommand.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import java.util.concurrent.ConcurrentHashMap; - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - - -public abstract class MongoCommand { - - private static final Logger logger = LoggerFactory.getLogger( MongoCommand.class ); - - static ConcurrentHashMap<String, MongoCommand> commands = new ConcurrentHashMap<String, MongoCommand>(); - - - @SuppressWarnings("unchecked") - public static MongoCommand getCommand( String commandName ) { - MongoCommand command = commands.get( commandName ); - if ( command != null ) { - return command; - } - - String clazz = "org.apache.usergrid.mongo.commands." + StringUtils.capitalize( commandName ); - - Class<MongoCommand> cls = null; - - try { - cls = ( Class<MongoCommand> ) Class.forName( clazz ); - } - catch ( ClassNotFoundException e ) { - logger.error( "Couldn't find command class", e ); - } - logger.debug( "using MongoCommand class {}", clazz ); - try { - if ( cls != null ) { - command = cls.newInstance(); - } - } - catch ( Exception e ) { - logger.error( "Couldn't find instantiate class", e ); - } - - if ( command != null ) { - MongoCommand oldCommand = commands.putIfAbsent( commandName, command ); - if ( oldCommand != null ) { - command = oldCommand; - } - } - else { - logger.warn( "Mongo command handler not found for " + commandName ); - } - - return command; - } - - - public abstract OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, - OpQuery opQuery ); -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ReplSetGetStatus.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ReplSetGetStatus.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ReplSetGetStatus.java deleted file mode 100644 index 0acee25..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ReplSetGetStatus.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class ReplSetGetStatus extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - OpReply reply = new OpReply( opQuery ); - reply.addDocument( map( entry( "errmsg", "not running with --replSet" ), entry( "ok", 0.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ServerStatus.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ServerStatus.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ServerStatus.java deleted file mode 100644 index 248b460..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/ServerStatus.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; -import org.apache.usergrid.utils.DateUtils; -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class ServerStatus extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - OpReply reply = new OpReply( opQuery ); - reply.addDocument( map( entry( "host", "api.usergrid.com:27017" ), entry( "version", "1.8.1" ), - entry( "process", "mongod" ), entry( "uptime", 1000.0 ), entry( "uptimeEstimate", 1000.0 ), - entry( "localTime", map( "$date", DateUtils.instance.iso8601DateNow() ) ), entry( "globalLock", - map( entry( "totalTime", 1.0 ), entry( "lockTime", 1000.0 ), entry( "ratio", 0.00001 ), - entry( "currentQueue", - map( entry( "total", 0 ), entry( "readers", 0 ), entry( "writers", 0 ) ) ), - entry( "activeClients", - map( entry( "total", 0 ), entry( "readers", 0 ), entry( "writers", 0 ) ) ) ) ), - entry( "mem", map( entry( "bits", 64 ), entry( "resident", 20 ), entry( "virtual", 2048 ), - entry( "supported", true ), entry( "mapped", 80 ) ) ), - entry( "connections", map( entry( "current", 1 ), entry( "available", 256 ) ) ), - entry( "extra_info", map( "note", "fields vary by platform" ) ), entry( "indexCounters", map( "btree", - map( entry( "accesses", 0 ), entry( "hits", 0 ), entry( "misses", 0 ), entry( "resets", 0 ), - entry( "missRatio", 0.0 ) ) ) ), entry( "backgroundFlushing", - map( entry( "flushes", 24 ), entry( "total_ms", 256 ), entry( "average_ms", 4.0 ), - entry( "last_ms", 16 ), - entry( "last_finished", map( "$date", DateUtils.instance.iso8601DateNow() ) ) ) ), - entry( "cursors", - map( entry( "totalOpen", 0 ), entry( "clientCursors_size", 0 ), entry( "timedOut", 0 ) ) ), - entry( "network", - map( entry( "bytesIn", 1024 ), entry( "bytesOut", 1024 ), entry( "numRequests", 32 ) ) ), - entry( "opcounters", - map( entry( "insert", 0 ), entry( "query", 1 ), entry( "update", 0 ), entry( "delete", 0 ), - entry( "getmore", 0 ), entry( "command", 1 ) ) ), entry( "asserts", - map( entry( "regular", 0 ), entry( "warning", 0 ), entry( "msg", 0 ), entry( "user", 0 ), - entry( "rollovers", 0 ) ) ), entry( "writeBacksQueued", false ), entry( "ok", 1.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Whatsmyuri.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Whatsmyuri.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Whatsmyuri.java deleted file mode 100644 index f236782..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Whatsmyuri.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.commands; - - -import java.net.InetSocketAddress; - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.protocol.OpQuery; -import org.apache.usergrid.mongo.protocol.OpReply; - -import static org.apache.usergrid.utils.MapUtils.entry; -import static org.apache.usergrid.utils.MapUtils.map; - - -public class Whatsmyuri extends MongoCommand { - - @Override - public OpReply execute( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent e, OpQuery opQuery ) { - InetSocketAddress addr = ( InetSocketAddress ) e.getRemoteAddress(); - OpReply reply = new OpReply( opQuery ); - reply.addDocument( - map( entry( "you", addr.getAddress().getHostAddress() + ":" + addr.getPort() ), entry( "ok", 1.0 ) ) ); - return reply; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/Message.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/Message.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/Message.java deleted file mode 100644 index 97f9579..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/Message.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.protocol; - - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import org.bson.BSONObject; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.apache.usergrid.mongo.utils.BSONUtils; -import org.apache.usergrid.utils.StringUtils; - - -public class Message { - - public static final int OP_REPLY = 1; // Reply to a client request - public static final int OP_MSG = 1000; // generic msg command - public static final int OP_UPDATE = 2001; // update document - public static final int OP_INSERT = 2002; // insert new document - public static final int RESERVED = 2003; // formerly used for OP_GET_BY_OID - public static final int OP_QUERY = 2004; // query a collection - public static final int OP_GET_MORE = 2005; // Get more data from a query - public static final int OP_DELETE = 2006; // Delete documents - public static final int OP_KILL_CURSORS = 2007; // Client done with cursor - - protected int messageLength; - protected int requestID; - protected int responseTo; - protected int opCode; - - - public Message() { - - } - - - public int getMessageLength() { - return messageLength; - } - - - public void setMessageLength( int messageLength ) { - this.messageLength = messageLength; - } - - - public int getRequestID() { - return requestID; - } - - - public void setRequestID( int requestID ) { - this.requestID = requestID; - } - - - public int getResponseTo() { - return responseTo; - } - - - public void setResponseTo( int responseTo ) { - this.responseTo = responseTo; - } - - - public int getOpCode() { - return opCode; - } - - - public void setOpCode( int opCode ) { - this.opCode = opCode; - } - - - public void decode( ChannelBuffer buffer ) throws IOException { - messageLength = buffer.readInt(); - requestID = buffer.readInt(); - responseTo = buffer.readInt(); - opCode = buffer.readInt(); - } - - - public ChannelBuffer encode( ChannelBuffer buffer ) { - if ( buffer == null ) { - buffer = ChannelBuffers.buffer( ByteOrder.LITTLE_ENDIAN, messageLength ); - } - buffer.writeInt( messageLength ); - buffer.writeInt( requestID ); - buffer.writeInt( responseTo ); - buffer.writeInt( opCode ); - return buffer; - } - - - public String readCString( ChannelBuffer buffer ) { - int i = buffer.bytesBefore( ( byte ) 0 ); - if ( i < 0 ) { - return null; - } - String s = buffer.toString( buffer.readerIndex(), i, Charset.forName( "UTF-8" ) ); - buffer.skipBytes( i + 1 ); - return s; - } - - - public void writeCString( String str, ChannelBuffer buffer ) { - if ( str != null ) { - buffer.writeBytes( str.getBytes( Charset.forName( "UTF-8" ) ) ); - } - buffer.writeByte( 0 ); - } - - - public ByteBuffer getCString( String str ) { - byte[] bytes = new byte[0]; - if ( str != null ) { - bytes = str.getBytes( Charset.forName( "UTF-8" ) ); - } - ByteBuffer buffer = ByteBuffer.allocate( bytes.length + 1 ); - buffer.put( bytes ); - buffer.rewind(); - return buffer; - } - - - public static List<ByteBuffer> encodeDocuments( List<BSONObject> documents ) { - List<ByteBuffer> encodedDocuments = new ArrayList<ByteBuffer>(); - if ( documents != null ) { - for ( BSONObject d : documents ) { - byte[] encoded = BSONUtils.encoder().encode( d ); - encodedDocuments.add( ByteBuffer.wrap( encoded ) ); - } - } - return encodedDocuments; - } - - - public static int buffersSize( List<ByteBuffer> buffers ) { - int l = 0; - for ( ByteBuffer b : buffers ) { - l += b.capacity(); - } - return l; - } - - - public static ByteBuffer encodeDocument( BSONObject document ) { - if ( document == null ) { - return ByteBuffer.allocate( 0 ); - } - return ByteBuffer.wrap( BSONUtils.encoder().encode( document ) ); - } - - - public static String getDatabaseName( String fullCollectionName ) { - return StringUtils.stringOrSubstringBeforeFirst( fullCollectionName, '.' ); - } - - - public static String getCollectionName( String fullCollectionName ) { - return StringUtils.stringOrSubstringAfterFirst( fullCollectionName, '.' ); - } - - - @Override - public String toString() { - return "Message [messageLength=" + messageLength + ", requestID=" + requestID + ", responseTo=" + responseTo - + ", opCode=" + opCode + "]"; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpCrud.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpCrud.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpCrud.java deleted file mode 100644 index ed83236..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpCrud.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.protocol; - - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; - - -public abstract class OpCrud extends Message { - - protected String fullCollectionName; - - - public String getFullCollectionName() { - return fullCollectionName; - } - - - public String getDatabaseName() { - return getDatabaseName( fullCollectionName ); - } - - - public String getCollectionName() { - return getCollectionName( fullCollectionName ); - } - - - /** Perform the operation */ - public abstract OpReply doOp( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent messageEvent ); -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java deleted file mode 100644 index be94463..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.protocol; - - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Map; -import java.util.UUID; - -import org.bson.BSONObject; -import org.bson.BasicBSONObject; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferInputStream; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.management.ApplicationInfo; -import org.apache.usergrid.mongo.MongoChannelHandler; -import org.apache.usergrid.mongo.query.MongoQueryParser; -import org.apache.usergrid.mongo.utils.BSONUtils; -import org.apache.usergrid.persistence.EntityManager; -import org.apache.usergrid.persistence.index.query.Query; -import org.apache.usergrid.persistence.Results; -import org.apache.usergrid.persistence.SimpleEntityRef; -import org.apache.usergrid.persistence.index.query.Identifier; -import org.apache.usergrid.persistence.index.query.Query.Level; -import org.apache.usergrid.security.shiro.utils.SubjectUtils; - - -public class OpDelete extends OpCrud { - - private static final Logger logger = LoggerFactory.getLogger( OpDelete.class ); - public static final int BATCH_SIZE = 1000; - - private int flags; - // delete query - private BSONObject selector; - - - public OpDelete() { - opCode = OP_DELETE; - } - - - public int getFlags() { - return flags; - } - - - public void setFlags( int flags ) { - this.flags = flags; - } - - - public BSONObject getSelector() { - return selector; - } - - - public void setSelector( BSONObject selector ) { - this.selector = selector; - } - - - public void setSelector( Map<?, ?> map ) { - selector = new BasicBSONObject(); - selector.putAll( map ); - } - - - @Override - public void decode( ChannelBuffer buffer ) throws IOException { - super.decode( buffer ); - buffer.readInt(); - fullCollectionName = readCString( buffer ); - flags = buffer.readInt(); - selector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ); - } - - - @Override - public ChannelBuffer encode( ChannelBuffer buffer ) { - int l = 24; // 6 ints * 4 bytes - - ByteBuffer fullCollectionNameBytes = getCString( fullCollectionName ); - l += fullCollectionNameBytes.capacity(); - - ByteBuffer selectorBytes = encodeDocument( selector ); - l += selectorBytes.capacity(); - - messageLength = l; - - buffer = super.encode( buffer ); - - buffer.writeInt( 0 ); - - buffer.writeBytes( fullCollectionNameBytes ); - - buffer.writeInt( flags ); - - buffer.writeBytes( selectorBytes ); - - return buffer; - } - - - /* - * (non-Javadoc) - * - * @see org.apache.usergrid.mongo.protocol.OpCrud#doOp(org.apache.usergrid.mongo. - * MongoChannelHandler, org.jboss.netty.channel.ChannelHandlerContext, - * org.jboss.netty.channel.MessageEvent) - */ - @Override - public OpReply doOp( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent messageEvent ) { - - // perform the query - Query query = MongoQueryParser.toNativeQuery( selector, 0 ); - - // TODO TN set an error - if ( query == null ) { - return null; - } - - query.setResultsLevel( Level.IDS ); - query.setLimit( BATCH_SIZE ); - - ApplicationInfo application = SubjectUtils.getApplication( Identifier.from( getDatabaseName() ) ); - - if ( application == null ) { - ctx.setAttachment( new IllegalArgumentException( - String.format( "Could not find application with name '%s' ", getDatabaseName() ) ) ); - return null; - } - - // delete every result - - EntityManager em = handler.getEmf().getEntityManager( application.getId() ); - - Results results = null; - - do { - - try { - - if ( results != null ) { - query.setCursor( results.getCursor() ); - } - - results = em.searchCollection( em.getApplicationRef(), getCollectionName(), query ); - - // now loop through all the ids and delete them - for ( UUID id : results.getIds() ) { - em.delete( new SimpleEntityRef( query.getEntityType(), id ) ); - } - } - catch ( Exception ex ) { - logger.error( "Unable to delete object", ex ); - ctx.setAttachment( ex ); - } - } - while ( results.getCursor() != null ); - - // return nothing on delete, like insert - - return null; - } - - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "OpDelete [flags=" + flags + ", selector=" + selector + ", fullCollectionName=" + fullCollectionName - + ", messageLength=" + messageLength + ", requestID=" + requestID + ", responseTo=" + responseTo - + ", opCode=" + opCode + "]"; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f552e7e/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpGetMore.java ---------------------------------------------------------------------- diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpGetMore.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpGetMore.java deleted file mode 100644 index 34622c9..0000000 --- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpGetMore.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 at - * - * 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 org.apache.usergrid.mongo.protocol; - - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.apache.usergrid.mongo.MongoChannelHandler; - - -public class OpGetMore extends OpCrud { - - int numberToReturn; - long cursorID; - - - public OpGetMore() { - opCode = OP_GET_MORE; - } - - - public int getNumberToReturn() { - return numberToReturn; - } - - - public void setNumberToReturn( int numberToReturn ) { - this.numberToReturn = numberToReturn; - } - - - public long getCursorID() { - return cursorID; - } - - - public void setCursorID( long cursorID ) { - this.cursorID = cursorID; - } - - - @Override - public void decode( ChannelBuffer buffer ) throws IOException { - super.decode( buffer ); - - buffer.readInt(); - fullCollectionName = readCString( buffer ); - numberToReturn = buffer.readInt(); - cursorID = buffer.readLong(); - } - - - @Override - public ChannelBuffer encode( ChannelBuffer buffer ) { - int l = 32; // 8 ints * 4 bytes - - ByteBuffer fullCollectionNameBytes = getCString( fullCollectionName ); - l += fullCollectionNameBytes.capacity(); - - messageLength = l; - - buffer = super.encode( buffer ); - - buffer.writeInt( 0 ); - - buffer.writeBytes( fullCollectionNameBytes ); - - buffer.writeInt( numberToReturn ); - - buffer.writeLong( cursorID ); - - return buffer; - } - - - /* (non-Javadoc) - * @see org.apache.usergrid.mongo.protocol.OpCrud#doOp(org.apache.usergrid.mongo.MongoChannelHandler, - * org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent) - */ - @Override - public OpReply doOp( MongoChannelHandler handler, ChannelHandlerContext ctx, MessageEvent messageEvent ) { - return new OpReply( this ); - } - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "OpGetMore [numberToReturn=" + numberToReturn + ", cursorID=" + cursorID + ", fullCollectionName=" - + fullCollectionName + ", messageLength=" + messageLength + ", requestID=" + requestID + ", responseTo=" - + responseTo + ", opCode=" + opCode + "]"; - } -}