Search in sources :

Example 1 with BucketOwner

use of com.emc.ecs.management.entity.BucketOwner in project ecs-dashboard by carone1.

the class ManagementClient method getBucketOwnerFromString.

/**
 * @param response
 * @return
 */
private BucketOwner getBucketOwnerFromString(String bucketKey, String response) {
    final String OWNER_SHIP = "ownerzone";
    final String TEXT_VALUE = "textValue:";
    final String DOUBLE_QUOTES = "\"";
    final String COLON = ":";
    final Pattern pattern = Pattern.compile("(?s)(.*?)" + OWNER_SHIP + "(.*?)" + TEXT_VALUE + "(.*?)" + DOUBLE_QUOTES + "(.*?)" + COLON + "(.*?)" + COLON + "(.*?)" + COLON + "(?<vdcid>.*?)" + DOUBLE_QUOTES + "(.*?)$");
    final Matcher matcher = pattern.matcher(response);
    String vdcId = null;
    while (matcher.find()) {
        vdcId = matcher.group("vdcid");
    }
    BucketOwner bucketOwner = new BucketOwner(vdcId, bucketKey);
    return bucketOwner;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BucketOwner(com.emc.ecs.management.entity.BucketOwner)

Example 2 with BucketOwner

use of com.emc.ecs.management.entity.BucketOwner in project ecs-dashboard by carone1.

the class ManagementClient method getBucketOwner.

/**
 * returns bucket owner list
 * @return
 */
public List<BucketOwner> getBucketOwner() {
    final WebResource mgmtResource = this.mgmtClient.resource(uri);
    StringBuilder restStr = new StringBuilder();
    restStr.append(REST_ALL_BUCKET_KEYS);
    // Get Namespace Detail Ressource
    WebResource getNamespaceDetailResource = mgmtResource.path(restStr.toString());
    String bucketKeyReponse = getNamespaceDetailResource.get(String.class);
    final List<BucketOwner> bucketOwners = new ArrayList<>();
    final Map<String, List<String>> urlBucketKeysmap = getUrlBucketKeyMap(bucketKeyReponse);
    urlBucketKeysmap.forEach((url, bucketKeys) -> {
        final String host = url.split("@@")[0];
        final String path = url.split("@@")[1];
        bucketKeys.forEach(bucketKey -> {
            WebResource getBucketDetailsResource = this.mgmtClient.resource(host).path(path).queryParam(REST_ALL_BUCKET_KEY_PARAMETER, bucketKey).queryParam(REST_ALL_BUCKET_VALUE_PARAMETER, "gpb").queryParam(REST_ALL_BUCKET_STYLE_PARAMETER, "raw");
            bucketOwners.add(getBucketOwnerFromString(bucketKey, getBucketDetailsResource.get(String.class)));
        });
    });
    return bucketOwners;
}
Also used : ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ArrayList(java.util.ArrayList) List(java.util.List) BucketOwner(com.emc.ecs.management.entity.BucketOwner)

Example 3 with BucketOwner

use of com.emc.ecs.management.entity.BucketOwner in project ecs-dashboard by carone1.

the class ElasticBucketOwnerDAO method insert.

@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
    if (bucketOwners != null && !bucketOwners.isEmpty()) {
        BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
        // Generate JSON for object buckets info
        for (BucketOwner bucketOwner : bucketOwners) {
            XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
            IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName).setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
            requestBuilder.add(request);
        }
        BulkResponse bulkResponse = requestBuilder.execute().actionGet();
        int items = bulkResponse.getItems().length;
        LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch" + "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
        if (bulkResponse.hasFailures()) {
            LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
        }
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) BucketOwner(com.emc.ecs.management.entity.BucketOwner) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with BucketOwner

use of com.emc.ecs.management.entity.BucketOwner in project ecs-dashboard by carone1.

the class FileVdcDAO method insert.

@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
    JAXBContext jaxbContext;
    for (BucketOwner bucketOwner : bucketOwners) {
        try {
            jaxbContext = JAXBContext.newInstance(BucketOwner.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            OutputStream byteOut = new ByteArrayOutputStream();
            jaxbMarshaller.marshal(bucketOwner, byteOut);
            String bytesOutStr = byteOut.toString();
            System.out.println(bytesOutStr);
            if (this.destinationPath != null) {
            // could write the formatted output to a file too
            }
        } catch (JAXBException e) {
            throw new RuntimeException(e.getLocalizedMessage());
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BucketOwner(com.emc.ecs.management.entity.BucketOwner)

Aggregations

BucketOwner (com.emc.ecs.management.entity.BucketOwner)4 WebResource (com.sun.jersey.api.client.WebResource)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1