Example usage for io.vertx.core MultiMap contains

List of usage examples for io.vertx.core MultiMap contains

Introduction

In this page you can find the example usage for io.vertx.core MultiMap contains.

Prototype

@GenIgnore(GenIgnore.PERMITTED_TYPE)
boolean contains(CharSequence name);

Source Link

Document

Like #contains(String) but accepting a CharSequence as a parameter

Usage

From source file:org.sfs.nodes.compute.masterkey.ReEncryptMasterKeys.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).flatMap(aVoid -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;/*  w  w  w  . j  a  v a 2  s  . c  o m*/

                MultiMap params = MultiMap.caseInsensitiveMultiMap();

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.RE_ENCRYPT_MASTER_KEYS, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.masterkey.VerifyRepairMasterKeys.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).flatMap(aVoid -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;// ww w . j  av  a2s.co m

                MultiMap params = MultiMap.caseInsensitiveMultiMap();

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.REPAIR_MASTER_KEYS, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.object.VerifyRepairObjectExecute.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).map(aVoid -> ObjectPath.fromSfsRequest(httpServerRequest))
            .map(new ValidateObjectPath()).flatMap(objectPath -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;//  ww w .ja  v a 2 s  . c o  m

                String unparsedForceRemoveVolumes = headers.contains(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        ? headers.get(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        : null;

                MultiMap params = MultiMap.caseInsensitiveMultiMap();
                if (unparsedForceRemoveVolumes != null) {
                    params.add(Jobs.Parameters.FORCE_REMOVE_VOLUMES, unparsedForceRemoveVolumes);
                }
                params.set(Jobs.Parameters.OBJECT_ID, objectPath.objectPath().get());

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.VERIFY_REPAIR_OBJECT, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.object.VerifyRepairObjectStop.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderExists(Jobs.Parameters.TIMEOUT))
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).map(aVoid -> ObjectPath.fromSfsRequest(httpServerRequest))
            .map(new ValidateObjectPath()).flatMap(objectPath -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : -1;// w  w  w .  ja  v a2  s. c  o m

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.stopJob(Jobs.ID.VERIFY_REPAIR_OBJECT, timeout, TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.object.VerifyRepairObjectWait.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderExists(Jobs.Parameters.TIMEOUT))
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).map(aVoid -> ObjectPath.fromSfsRequest(httpServerRequest))
            .map(new ValidateObjectPath()).flatMap(objectPath -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : -1;//from  w w w  . j a va 2 s . c  o m

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.waitForJob(Jobs.ID.VERIFY_REPAIR_OBJECT, timeout, TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.data.ChecksumBlob.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest))
            .map(new ValidateNodeIsDataNode<>(vertxContext)).map(aVoid -> httpServerRequest)
            .map(new ValidateParamExists(VOLUME)).map(new ValidateParamExists(POSITION))
            .map(new ValidateParamBetweenLong(POSITION, 0, MAX_VALUE))
            .map(new ValidateParamBetweenLong(LENGTH, 0, MAX_VALUE))
            .map(new ValidateParamBetweenLong(OFFSET, 0, MAX_VALUE)).map(new ValidateParamComputedDigest())
            .flatMap(httpServerRequest1 -> {
                MultiMap params = httpServerRequest1.params();

                final Iterable<MessageDigestFactory> iterable = from(params.names())
                        .transform(new Function<String, Optional<MessageDigestFactory>>() {
                            @Override
                            public Optional<MessageDigestFactory> apply(String param) {
                                Matcher matcher = COMPUTED_DIGEST.matcher(param);
                                if (matcher.matches()) {
                                    String digestName = matcher.group(1);
                                    return fromValueIfExists(digestName);
                                }//www  .  ja  v  a 2  s . c o  m
                                return absent();
                            }
                        }).filter(Optional::isPresent).transform(input -> input.get());

                MultiMap queryParams = httpServerRequest1.params();

                String volumeId = queryParams.get(VOLUME);
                long position = parseLong(queryParams.get(POSITION));

                Optional<Long> oOffset;
                if (queryParams.contains(OFFSET)) {
                    oOffset = of(parseLong(queryParams.get(OFFSET)));
                } else {
                    oOffset = absent();
                }

                Optional<Long> oLength;
                if (queryParams.contains(LENGTH)) {
                    oLength = of(parseLong(queryParams.get(LENGTH)));
                } else {
                    oLength = absent();
                }

                // let the client know we're alive by sending pings on the response stream
                httpServerRequest1.startProxyKeepAlive();

                LocalNode localNode = new LocalNode(vertxContext,
                        vertxContext.verticle().nodes().volumeManager());

                return localNode
                        .checksum(volumeId, position, oOffset, oLength,
                                toArray(iterable, MessageDigestFactory.class))
                        .map(digestBlobOptional -> new Holder2<>(httpServerRequest1, digestBlobOptional));
            }).flatMap(holder -> httpServerRequest.stopKeepAlive().map(aVoid -> holder))
            .onErrorResumeNext(throwable -> httpServerRequest.stopKeepAlive()
                    .flatMap(aVoid -> Observable.<Holder2<SfsRequest, Optional<DigestBlob>>>error(throwable)))
            .single().onErrorResumeNext(new HandleServerToBusy<>())
            .subscribe(new Terminus<Holder2<SfsRequest, Optional<DigestBlob>>>(httpServerRequest) {
                @Override
                public void onNext(Holder2<SfsRequest, Optional<DigestBlob>> holder) {
                    Optional<DigestBlob> oJsonDigestBlob = holder.value1();
                    JsonObject jsonResponse = new JsonObject();
                    if (oJsonDigestBlob.isPresent()) {
                        jsonResponse.put("code", HTTP_OK).put("blob", oJsonDigestBlob.get().toJsonObject());
                    } else {
                        jsonResponse.put("code", HTTP_NOT_FOUND);
                    }
                    HttpServerResponse httpResponse = holder.value0().response();
                    httpResponse.write(jsonResponse.encode(), UTF_8.toString()).write(DELIMITER_BUFFER);
                }
            });

}

From source file:org.sfs.nodes.data.GetBlob.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest))
            .map(new ValidateNodeIsDataNode<>(vertxContext)).map(aVoid -> httpServerRequest)
            .map(new ValidateParamExists(VOLUME)).map(new ValidateParamExists(POSITION))
            .map(new ValidateParamBetweenLong(POSITION, 0, MAX_VALUE))
            .map(new ValidateParamBetweenLong(LENGTH, 0, MAX_VALUE))
            .map(new ValidateParamBetweenLong(OFFSET, 0, MAX_VALUE)).flatMap(httpServerRequest1 -> {

                httpServerRequest1.response().setChunked(true);

                MultiMap queryParams = httpServerRequest1.params();

                String volumeId = queryParams.get(VOLUME);
                long position = parseLong(queryParams.get(POSITION));

                Optional<Long> oOffset;
                if (queryParams.contains(OFFSET)) {
                    oOffset = of(parseLong(queryParams.get(OFFSET)));
                } else {
                    oOffset = absent();//  ww  w  . j  ava  2  s  .  co  m
                }

                Optional<Long> oLength;
                if (queryParams.contains(LENGTH)) {
                    oLength = of(parseLong(queryParams.get(LENGTH)));
                } else {
                    oLength = absent();
                }

                final Volume volume = vertxContext.verticle().nodes().volumeManager().get(volumeId).get();

                return volume
                        .getDataStream(httpServerRequest1.vertxContext().vertx(), position, oOffset, oLength)
                        .map(readStreamBlob -> new Holder2<>(httpServerRequest1, readStreamBlob));
            }).map(new WriteHeaderBlobAsHttpResponseHeaders<>())
            .map(new WriteReadStreamBlobAsHttpResponseHeaders<>()).flatMap(input -> {
                Optional<ReadStreamBlob> oReadStreamBlob = input.value1();
                if (oReadStreamBlob.isPresent()) {
                    ReadStreamBlob readStreamBlob = oReadStreamBlob.get();
                    HttpServerResponse httpServerResponse = input.value0().response();
                    httpServerResponse.setStatusCode(HTTP_OK);
                    NoEndEndableWriteStream endableWriteStream = new NoEndEndableWriteStream(
                            new HttpServerResponseEndableWriteStream(httpServerResponse));
                    return readStreamBlob.produce(endableWriteStream);
                } else {
                    input.value0().response().setStatusCode(HTTP_NOT_FOUND);
                }
                return aVoid();
            }).single().onErrorResumeNext(new HandleServerToBusy<>())
            .subscribe(new Terminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    // do nothing here since we had to write the status before the stream was written
                }
            });

}

From source file:org.sfs.nodes.master.MasterNodeExecuteJob.java

License:Apache License

@Override
public void handle(SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest))
            .map(new ValidateNodeIsMasterNode<>(vertxContext)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderExists(Jobs.Parameters.JOB_ID))
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).flatMap(aVoid -> {

                MultiMap headers = httpServerRequest.headers();
                String jobId = headers.get(JOB_ID);

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : -1;/*from w w w .j ava 2  s .c  o  m*/

                httpServerRequest.startProxyKeepAlive();

                Jobs jobs = vertxContext.verticle().jobs();
                return Defer.aVoid().doOnNext(
                        aVoid1 -> jobs.execute(vertxContext, jobId, headers).subscribe(new NullSubscriber<>()))
                        .flatMap(aVoid1 -> {
                            if (timeout >= 0) {
                                return jobs.waitStopped(vertxContext, jobId, timeout, TimeUnit.MILLISECONDS);
                            } else {
                                return Defer.aVoid();
                            }
                        });
            }).single().subscribe(new Terminus<Void>(httpServerRequest) {

                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.master.MasterNodeStopJob.java

License:Apache License

@Override
public void handle(SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest))
            .map(new ValidateNodeIsMasterNode<>(vertxContext)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderExists(Jobs.Parameters.JOB_ID))
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).flatMap(aVoid -> {

                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : -1;/*  www .  j a v  a  2s.c  o m*/

                String jobId = headers.get(Jobs.Parameters.JOB_ID);

                httpServerRequest.startProxyKeepAlive();

                Jobs jobs = vertxContext.verticle().jobs();
                return Defer.aVoid().flatMap(aVoid1 -> jobs.stop(vertxContext, jobId)).flatMap(aVoid1 -> {
                    if (timeout >= 0) {
                        return jobs.waitStopped(vertxContext, jobId, timeout, TimeUnit.MILLISECONDS);
                    } else {
                        return Defer.aVoid();
                    }
                });
            }).single().subscribe(new Terminus<Void>(httpServerRequest) {

                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.master.MasterNodeWaitForJob.java

License:Apache License

@Override
public void handle(SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest))
            .map(new ValidateNodeIsMasterNode<>(vertxContext)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderExists(Jobs.Parameters.JOB_ID))
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).flatMap(aVoid -> {

                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : -1;//from   ww  w  .  j a va 2  s.com

                String jobId = headers.get(Jobs.Parameters.JOB_ID);

                httpServerRequest.startProxyKeepAlive();

                Jobs jobs = vertxContext.verticle().jobs();
                return Defer.aVoid().flatMap(aVoid1 -> {
                    if (timeout >= 0) {
                        return jobs.waitStopped(vertxContext, jobId, timeout, TimeUnit.MILLISECONDS);
                    } else {
                        return Defer.aVoid();
                    }
                });
            }).single().subscribe(new Terminus<Void>(httpServerRequest) {

                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}