Permalink
Browse files

saving.

  • Loading branch information...
1 parent f287316 commit b060bcf55db8d3f4d562d8755dc92cc4e605d17c Neil committed Aug 3, 2009
View
@@ -98,6 +98,7 @@
</target>
<target name="clean-core" depends="clean-msgs">
<ant dir="modules/core" inheritall="false" target="clean"/>
+ <ant dir="modules/wsstack" inheritall="false" target="clean"/>
</target>
<target name="clean-www" depends="clean-eucalyptus-ws">
<ant dir="modules/www" inheritall="false" target="clean"/>
@@ -130,7 +130,8 @@ public class EucalyptusErrorMessageType extends EucalyptusMessage {
String source;
String message;
String requestType = "not available";
-
+ Throwable exception;
+
public EucalyptusErrorMessageType() {}
public EucalyptusErrorMessageType(String source, String message)
@@ -5,7 +5,7 @@
import org.jboss.netty.handler.codec.http.HttpVersion;
public class MappingHttpResponse extends MappingHttpMessage implements HttpResponse {
- private final HttpResponseStatus status;
+ private HttpResponseStatus status;
public MappingHttpResponse( HttpVersion version ) {
super( version );
@@ -1,24 +1,156 @@
package com.eucalyptus.ws.handlers;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.List;
+
import com.eucalyptus.ws.MappingHttpResponse;
+import org.apache.commons.httpclient.HttpStatus;
import org.apache.log4j.Logger;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import edu.ucsb.eucalyptus.msgs.*;
+import edu.ucsb.eucalyptus.cloud.AccessDeniedException;
+import edu.ucsb.eucalyptus.cloud.BucketAlreadyExistsException;
+import edu.ucsb.eucalyptus.cloud.BucketAlreadyOwnedByYouException;
+import edu.ucsb.eucalyptus.cloud.BucketNotEmptyException;
+import edu.ucsb.eucalyptus.cloud.DecryptionFailedException;
+import edu.ucsb.eucalyptus.cloud.EntityTooLargeException;
+import edu.ucsb.eucalyptus.cloud.ImageAlreadyExistsException;
+import edu.ucsb.eucalyptus.cloud.NoSuchBucketException;
+import edu.ucsb.eucalyptus.cloud.NoSuchEntityException;
+import edu.ucsb.eucalyptus.cloud.NotAuthorizedException;
+import edu.ucsb.eucalyptus.cloud.NotImplementedException;
+import edu.ucsb.eucalyptus.cloud.NotModifiedException;
+import edu.ucsb.eucalyptus.cloud.PreconditionFailedException;
+import edu.ucsb.eucalyptus.cloud.TooManyBucketsException;
+import edu.ucsb.eucalyptus.msgs.WalrusBucketErrorMessageType;
+
public class WalrusOutboundHandler extends MessageStackHandler {
private static Logger LOG = Logger.getLogger( WalrusOutboundHandler.class );
+ private static String ipAddress;
+ private static int SC_DECRYPTION_FAILED = 566;
+
+ static {
+ ipAddress = "127.0.0.1";
+ List<NetworkInterface> ifaces = null;
+ try {
+ ifaces = Collections.list( NetworkInterface.getNetworkInterfaces() );
+ } catch ( SocketException e1 ) {}
+
+ for ( NetworkInterface iface : ifaces ) {
+ try {
+ if ( !iface.isLoopback() && !iface.isVirtual() && iface.isUp() ) {
+ for ( InetAddress iaddr : Collections.list( iface.getInetAddresses() ) ) {
+ if ( !iaddr.isSiteLocalAddress() && !( iaddr instanceof Inet6Address) ) {
+ ipAddress = iaddr.getHostAddress();
+ break;
+ }
+ }
+ }
+ } catch ( SocketException e1 ) {}
+ }
+ }
+
+
+ @Override
+ public void incomingMessage( ChannelHandlerContext ctx, MessageEvent event ) throws Exception {
+
+ }
@Override
public void outgoingMessage( ChannelHandlerContext ctx, MessageEvent event ) throws Exception {
if ( event.getMessage( ) instanceof MappingHttpResponse ) {
MappingHttpResponse httpResponse = ( MappingHttpResponse ) event.getMessage( );
EucalyptusMessage msg = (EucalyptusMessage) httpResponse.getMessage( );
- if(msg instanceof WalrusDeleteResponseType) {
+ if(msg instanceof EucalyptusErrorMessageType) {
+ EucalyptusErrorMessageType errorMessage = (EucalyptusErrorMessageType) msg;
+ EucalyptusMessage errMsg;
+ Throwable ex = errorMessage.getException();
+ if ( ex instanceof NoSuchBucketException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchBucketException ) ex ).getBucketName(), "NoSuchBucket", "The specified bucket was not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof AccessDeniedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( AccessDeniedException ) ex ).getBucketName(), "AccessDenied", "No U", HttpStatus.SC_FORBIDDEN, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof NotAuthorizedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotAuthorizedException ) ex ).getValue(), "Unauthorized", "No U", HttpStatus.SC_UNAUTHORIZED, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketAlreadyOwnedByYouException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyOwnedByYouException ) ex ).getBucketName(), "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.", HttpStatus.SC_CONFLICT, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketAlreadyExistsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyExistsException ) ex ).getBucketName(), "BucketAlreadyExists", "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.", HttpStatus.SC_CONFLICT, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketNotEmptyException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketNotEmptyException ) ex ).getBucketName(), "BucketNotEmpty", "The bucket you tried to delete is not empty.", HttpStatus.SC_CONFLICT, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof PreconditionFailedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( PreconditionFailedException ) ex ).getPrecondition(), "PreconditionFailed", "At least one of the pre-conditions you specified did not hold.", HttpStatus.SC_PRECONDITION_FAILED, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof NotModifiedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotModifiedException ) ex ).getPrecondition(), "NotModified", "Object Not Modified", HttpStatus.SC_NOT_MODIFIED, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof TooManyBucketsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( TooManyBucketsException ) ex ).getBucketName(), "TooManyBuckets", "You have attempted to create more buckets than allowed.", HttpStatus.SC_BAD_REQUEST, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof EntityTooLargeException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( EntityTooLargeException ) ex ).getEntityName(), "EntityTooLarge", "Your proposed upload exceeds the maximum allowed object size.", HttpStatus.SC_BAD_REQUEST, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof NoSuchEntityException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchEntityException ) ex ).getBucketName(), "NoSuchEntity", "The specified entity was not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof DecryptionFailedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( DecryptionFailedException ) ex ).getValue(), "Decryption Failed", "Fail", SC_DECRYPTION_FAILED, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof ImageAlreadyExistsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( ImageAlreadyExistsException ) ex ).getValue(), "Image Already Exists", "Fail", HttpStatus.SC_CONFLICT, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ }
+ else if ( ex instanceof NotImplementedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotImplementedException ) ex ).getValue(), "Not Implemented", "NA", HttpStatus.SC_NOT_IMPLEMENTED, msg.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( msg.getCorrelationId() );
+ } else {
+ errMsg = errorMessage;
+ }
+ httpResponse.setMessage(errMsg);
+
+ } else if(msg instanceof WalrusDeleteResponseType) {
httpResponse.setStatus(HttpResponseStatus.NO_CONTENT);
}
}
}
-
+
}
@@ -52,6 +52,7 @@
import edu.ucsb.eucalyptus.msgs.AccessControlListType;
import edu.ucsb.eucalyptus.msgs.AccessControlPolicyType;
import edu.ucsb.eucalyptus.msgs.CanonicalUserType;
+import edu.ucsb.eucalyptus.msgs.EucalyptusErrorMessageType;
import edu.ucsb.eucalyptus.msgs.EucalyptusMessage;
import edu.ucsb.eucalyptus.msgs.GetObjectResponseType;
import edu.ucsb.eucalyptus.msgs.GetObjectType;
@@ -84,7 +85,7 @@
private LinkedBlockingQueue<WalrusDataMessage> putQueue;
private GetObjectType getObjectType;
public static Channel channel;
-
+
@Override
public void incomingMessage( ChannelHandlerContext ctx, MessageEvent event ) throws Exception {
if ( event.getMessage( ) instanceof MappingHttpRequest ) {
@@ -108,48 +109,20 @@ public void outgoingMessage( ChannelHandlerContext ctx, MessageEvent event ) thr
if ( event.getMessage( ) instanceof MappingHttpResponse ) {
MappingHttpResponse httpResponse = ( MappingHttpResponse ) event.getMessage( );
EucalyptusMessage msg = (EucalyptusMessage) httpResponse.getMessage( );
- if(false) { //msg instanceof GetObjectResponseType) {
- GetObjectResponseType getObjectResponse = (GetObjectResponseType) msg;
- Long size = getObjectResponse.getSize();
- String etag = getObjectResponse.getEtag();
- httpResponse.addHeader( HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(size) );
- httpResponse.addHeader( HttpHeaders.Names.CONTENT_TYPE, "binary/octet-stream" );
- Channel channel = ctx.getChannel();
- channel.write(httpResponse);
- WalrusDataMessenger messenger = getReadMessenger();
- LinkedBlockingQueue<WalrusDataMessage> getQueue = messenger.getQueue(getObjectType.getKey(), getObjectType.getRandomKey());
-
- WalrusDataMessage dataMessage;
- try {
- while ((dataMessage = getQueue.take())!=null) {
- if(WalrusDataMessage.isStart(dataMessage)) {
- //TODO: should read size and verify
- } else if(WalrusDataMessage.isData(dataMessage)) {
- byte[] data = dataMessage.getPayload();
- LOG.warn("writing data message");
- channel.write(data);
- } else {
- return;
- }
- }
- } catch (InterruptedException ex) {
- LOG.error(ex, ex);
- }
+ Binding binding;
+ if(!(msg instanceof EucalyptusErrorMessageType)) {
+ binding = BindingManager.getBinding( BindingManager.sanitizeNamespace( namespace ) );
} else {
- Binding binding = BindingManager.getBinding( BindingManager.sanitizeNamespace( namespace ) );
- if(httpResponse.getMessage() != null) {
- if(!(httpResponse.getMessage() instanceof GetObjectResponseType)) {
- OMElement omMsg = binding.toOM( httpResponse.getMessage( ) );
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- omMsg.serialize( byteOut );
- byte[] req = byteOut.toByteArray();
- ChannelBuffer buffer = ChannelBuffers.copiedBuffer( req );
- httpResponse.addHeader( HttpHeaders.Names.CONTENT_LENGTH, String.valueOf( buffer.readableBytes() ) );
- httpResponse.addHeader( HttpHeaders.Names.CONTENT_TYPE, "text/plain" );
- httpResponse.setContent( buffer );
- }
- }
+ binding = BindingManager.getBinding( BindingManager.sanitizeNamespace( "http://msgs.eucalyptus.ucsb.edu" ) );
}
+ OMElement omMsg = binding.toOM( httpResponse.getMessage( ) );
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ omMsg.serialize( byteOut );
+ byte[] req = byteOut.toByteArray();
+ ChannelBuffer buffer = ChannelBuffers.copiedBuffer( req );
+ httpResponse.addHeader( HttpHeaders.Names.CONTENT_LENGTH, String.valueOf( buffer.readableBytes() ) );
+ httpResponse.addHeader( HttpHeaders.Names.CONTENT_TYPE, "text/plain" );
+ httpResponse.setContent( buffer );
}
}
@@ -1118,12 +1091,12 @@ private void handleFirstChunk(MappingHttpRequest httpRequest, long dataLength) {
}
- public static synchronized WalrusDataMessenger getReadMessenger() {
- if (getMessenger == null) {
- getMessenger = new WalrusDataMessenger();
- }
- return getMessenger;
- }
+ public static synchronized WalrusDataMessenger getReadMessenger() {
+ if (getMessenger == null) {
+ getMessenger = new WalrusDataMessenger();
+ }
+ return getMessenger;
+ }
public static synchronized WalrusDataMessenger getWriteMessenger() {
@@ -13,6 +13,7 @@
import com.eucalyptus.ws.stages.HmacV2UserAuthenticationStage;
import com.eucalyptus.ws.stages.QueryBindingStage;
import com.eucalyptus.ws.stages.UnrollableStage;
+import com.eucalyptus.ws.stages.WalrusOutboundStage;
import com.eucalyptus.ws.stages.WalrusRESTBindingStage;
import com.eucalyptus.ws.stages.WalrusUserAuthenticationStage;
import com.eucalyptus.ws.util.WalrusProperties;
@@ -25,7 +26,7 @@
protected void addStages( List<UnrollableStage> stages ) {
stages.add( new WalrusUserAuthenticationStage( ) );
stages.add( new WalrusRESTBindingStage( ) );
-
+ stages.add( new WalrusOutboundStage());
}
@Override
@@ -6,6 +6,7 @@
import com.eucalyptus.ws.handlers.QueryTimestampHandler;
import com.eucalyptus.ws.handlers.RestfulMarshallingHandler;
import com.eucalyptus.ws.handlers.WalrusAuthenticationHandler;
+import com.eucalyptus.ws.handlers.WalrusOutboundHandler;
public class WalrusOutboundStage implements UnrollableStage {
Oops, something went wrong.

0 comments on commit b060bcf

Please sign in to comment.