Search in sources :

Example 6 with ServiceHost

use of com.vmware.xenon.common.ServiceHost in project photon-model by vmware.

the class ServerX509TrustManagerTest method setUp.

@BeforeClass
public static void setUp() throws Throwable {
    // Force a custom trust store... that shouldn't override the Java default cacerts.
    URI customStore = ServerX509TrustManagerTest.class.getResource("/certs/trusted_certificates.jks").toURI();
    File f = new File(customStore.getPath());
    System.setProperty(ServerX509TrustManager.JAVAX_NET_SSL_TRUST_STORE, f.getPath());
    System.setProperty(ServerX509TrustManager.JAVAX_NET_SSL_TRUST_STORE_PASSWORD, "changeit");
    // Fake host, not really needed for the purpose of the trust manager test.
    ServiceHost host = new ServiceHost() {
    };
    trustManager = ServerX509TrustManager.init(host);
}
Also used : URI(java.net.URI) File(java.io.File) ServiceHost(com.vmware.xenon.common.ServiceHost) BeforeClass(org.junit.BeforeClass)

Example 7 with ServiceHost

use of com.vmware.xenon.common.ServiceHost in project photon-model by vmware.

the class SslTrustCertificateServiceUtils method subscribe.

/**
 * Subscribes a consumer to the given continuous query.
 */
static void subscribe(ServiceHost host, Consumer<Operation> consumer) {
    QueryTask task = getQueryTask();
    QueryUtils.createQueryTaskOperation(host, task, null).setReferer(host.getUri()).setCompletion((o, e) -> {
        if (e != null && o.getStatusCode() != Operation.STATUS_CODE_CONFLICT) {
            host.log(Level.SEVERE, Utils.toString(e));
            return;
        }
        String taskUriPath = UriUtils.buildUriPath(ServiceUriPaths.CORE_LOCAL_QUERY_TASKS, task.documentSelfLink);
        Operation subscribePost = Operation.createPost(host, taskUriPath).setReferer(host.getUri()).setConnectionSharing(true).setCompletion((op, ex) -> {
            if (ex != null) {
                host.log(Level.SEVERE, Utils.toString(ex));
            }
        });
        host.log(Level.INFO, "Subscribing to a continuous task: %s", taskUriPath);
        host.startSubscriptionService(subscribePost, consumer, ServiceSubscriber.create(false));
    }).sendWith(host);
}
Also used : Operation(com.vmware.xenon.common.Operation) QueryTask(com.vmware.xenon.services.common.QueryTask) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) UUID(java.util.UUID) ServiceHost(com.vmware.xenon.common.ServiceHost) ServiceSubscriber(com.vmware.xenon.common.ServiceSubscriptionState.ServiceSubscriber) Level(java.util.logging.Level) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) QueryStrategy(com.vmware.photon.controller.model.query.QueryStrategy) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Aggregations

ServiceHost (com.vmware.xenon.common.ServiceHost)7 URI (java.net.URI)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Level (java.util.logging.Level)4 Collectors (java.util.stream.Collectors)4 Operation (com.vmware.xenon.common.Operation)3 Utils (com.vmware.xenon.common.Utils)3 TimeUnit (java.util.concurrent.TimeUnit)3 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)2 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 UriUtils (com.vmware.xenon.common.UriUtils)2 Query (com.vmware.xenon.services.common.QueryTask.Query)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 UUID (java.util.UUID)2 Consumer (java.util.function.Consumer)2