Search in sources :

Example 1 with ReplicationConfiguration

use of com.pspace.ifs.ksan.gw.format.ReplicationConfiguration in project ksan by infinistor.

the class PutBucketReplication method checkBucketReplication.

private void checkBucketReplication(String replicationXml) throws GWException {
    XmlMapper xmlMapper = new XmlMapper();
    ReplicationConfiguration rc;
    try {
        rc = xmlMapper.readValue(replicationXml, ReplicationConfiguration.class);
    } catch (JsonMappingException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    } catch (JsonProcessingException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    }
    Map<String, String> id = new HashMap<String, String>();
    if (rc.rules != null) {
        logger.warn(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULES, rc.rules.toString());
        for (Rule rl : rc.rules) {
            logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_ID, rl.id);
            logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PREFIX, rl.prefix);
            logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PRIORITY, rl.priority);
            if (rl.id != null) {
                if (rl.id.length() > 255) {
                    throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
                }
                id.put(rl.id, rl.id);
            } else {
                // length is bounded by 7
                byte[] array = new byte[7];
                new Random().nextBytes(array);
                String generatedString = new String(array, Charset.forName(GWConstants.CHARSET_UTF_8));
                id.put(generatedString, generatedString);
            }
            if (rl.existingObjectReplication != null) {
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION, rl.existingObjectReplication);
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION_STATUS, rl.existingObjectReplication.status);
            }
            if (rl.filter != null) {
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER, rl.filter);
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND, rl.filter.and);
                if (rl.filter.and != null) {
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_PREFIX, rl.filter.and.prefix);
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG, rl.filter.and.tag);
                    if (rl.filter.and.tag != null) {
                        for (Tag r : rl.filter.and.tag) {
                            logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_KEY, r.key);
                            logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_VALUE, r.value);
                        }
                    }
                }
            }
            if (rl.sourceSelectionCriteria != null) {
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA, rl.sourceSelectionCriteria);
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS, rl.sourceSelectionCriteria.replicaModifications);
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS_STATUS, rl.sourceSelectionCriteria.replicaModifications.status);
                if (rl.sourceSelectionCriteria.sseKmsEncryptedObjects != null) {
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects);
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS_STATUS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects.status);
                }
            }
            if (rl.deleteMarkerReplication != null && rl.deleteMarkerReplication.Status != null) {
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION, rl.deleteMarkerReplication);
                logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION_STATUS, rl.deleteMarkerReplication.Status);
                if (rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
                    logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
                    throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
                }
            }
            if (rl.destination == null) {
                throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
            } else {
                if (rl.destination.bucket != null) {
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_BUCKET, rl.destination.bucket);
                    String[] arnPath = rl.destination.bucket.split(GWConstants.COLON, -1);
                    if (arnPath.length != 6) {
                        logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
                        throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                    }
                    if (Strings.isNullOrEmpty(arnPath[5])) {
                        logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
                        throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                    }
                    if (Strings.isNullOrEmpty(arnPath[3])) {
                        if (isExistBucket(arnPath[5])) {
                            throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                        }
                        Bucket destBucket = getSomeBucket(arnPath[5]);
                        if (destBucket.getVersioning() != null) {
                            if (!GWConstants.STATUS_ENABLED.equalsIgnoreCase(destBucket.getVersioning())) {
                                throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                            }
                        } else {
                            throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                        }
                    }
                } else {
                    logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
                    throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
                }
                if (rl.destination.accessControlTranslation != null) {
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION, rl.destination.accessControlTranslation);
                    if (rl.destination.accessControlTranslation.owner != null) {
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION_OWNER, rl.destination.accessControlTranslation.owner);
                    }
                    if (rl.destination.encryptionConfiguration != null) {
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION, rl.destination.encryptionConfiguration);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION_REPLICAT_KMS_KEY_ID, rl.destination.encryptionConfiguration.replicaKmsKeyID);
                    }
                    if (rl.destination.metrics != null) {
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS, rl.destination.metrics);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD, rl.destination.metrics.eventThreshold);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD_MINUTES, rl.destination.metrics.eventThreshold.minutes);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_STATUS, rl.destination.metrics.status);
                    }
                    if (rl.destination.replicationTime != null) {
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME, rl.destination.replicationTime);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_STATUS, rl.destination.replicationTime.status);
                        logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_TIME, rl.destination.replicationTime.time);
                    }
                }
                if (rl.destination.storageClass != null) {
                    logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_STORAGE_CLASS, rl.destination.storageClass);
                    logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
                    throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
                }
            }
            if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
                if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
                    logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
                    throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
                }
            }
            if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
                if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
                    logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
                    throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
                }
            }
            if (rl.sourceSelectionCriteria != null) {
                logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
                throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
            }
            if (rl.status != null && rl.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
                logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
                throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
            }
        }
        if (rc.rules.size() > id.size()) {
            logger.error(GWErrorCode.INVALID_ARGUMENT.getMessage());
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
    }
}
Also used : HashMap(java.util.HashMap) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Random(java.util.Random) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) Bucket(com.pspace.ifs.ksan.objmanager.Bucket) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Rule(com.pspace.ifs.ksan.gw.format.ReplicationConfiguration.Rule) Tag(com.pspace.ifs.ksan.gw.format.ReplicationConfiguration.Rule.Filter.And.Tag) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ReplicationConfiguration(com.pspace.ifs.ksan.gw.format.ReplicationConfiguration)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 ReplicationConfiguration (com.pspace.ifs.ksan.gw.format.ReplicationConfiguration)1 Rule (com.pspace.ifs.ksan.gw.format.ReplicationConfiguration.Rule)1 Tag (com.pspace.ifs.ksan.gw.format.ReplicationConfiguration.Rule.Filter.And.Tag)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 Bucket (com.pspace.ifs.ksan.objmanager.Bucket)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1