Search in sources :

Example 1 with VipStatusConfig

use of com.yahoo.container.core.VipStatusConfig in project vespa by vespa-engine.

the class VipStatusHandlerTestCase method testFileFound.

@Test
public final void testFileFound() throws IOException {
    final File statusFile = File.createTempFile("VipStatusHandlerTestCase", null);
    try {
        final FileWriter writer = new FileWriter(statusFile);
        final String OK = "OK\n";
        writer.write(OK);
        writer.close();
        final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true).statusfile(statusFile.getAbsolutePath()).noSearchBackendsImpliesOutOfService(false));
        final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
        final MockResponseHandler responseHandler = new MockResponseHandler();
        final HttpRequest request = createRequest();
        final BufferedContentChannel requestContent = createChannel();
        handler.handleRequest(request, requestContent, responseHandler);
        final ByteBuffer b = responseHandler.channel.read();
        final byte[] asBytes = new byte[b.remaining()];
        b.get(asBytes);
        assertEquals(OK, Utf8.toString(asBytes));
    } finally {
        statusFile.delete();
    }
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) FileWriter(java.io.FileWriter) VipStatusConfig(com.yahoo.container.core.VipStatusConfig) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with VipStatusConfig

use of com.yahoo.container.core.VipStatusConfig in project vespa by vespa-engine.

the class VipStatusHandlerTestCase method testProgrammaticallyRemovedFromRotation.

@Test
public final void testProgrammaticallyRemovedFromRotation() throws IOException {
    VipStatus vipStatus = new VipStatus();
    final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false).noSearchBackendsImpliesOutOfService(true));
    final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus);
    vipStatus.removeFromRotation(this);
    {
        final MockResponseHandler responseHandler = new MockResponseHandler();
        final HttpRequest request = createRequest();
        final BufferedContentChannel requestContent = createChannel();
        handler.handleRequest(request, requestContent, responseHandler);
        final ByteBuffer b = responseHandler.channel.read();
        final byte[] asBytes = new byte[b.remaining()];
        b.get(asBytes);
        assertEquals(VipStatusHandler.StatusResponse.NO_SEARCH_BACKENDS, Utf8.toString(asBytes));
    }
    vipStatus.addToRotation(this);
    {
        final MockResponseHandler responseHandler = new MockResponseHandler();
        final HttpRequest request = createRequest();
        final BufferedContentChannel requestContent = createChannel();
        handler.handleRequest(request, requestContent, responseHandler);
        final ByteBuffer b = responseHandler.channel.read();
        final byte[] asBytes = new byte[b.remaining()];
        b.get(asBytes);
        assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes));
    }
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) VipStatusConfig(com.yahoo.container.core.VipStatusConfig) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with VipStatusConfig

use of com.yahoo.container.core.VipStatusConfig in project vespa by vespa-engine.

the class ContainerModelBuilderTest method vip_status_handler_uses_file_for_hosted_vespa.

@Test
public void vip_status_handler_uses_file_for_hosted_vespa() throws Exception {
    String servicesXml = "<services>" + "<jdisc version='1.0'>" + nodesXml + "</jdisc>" + "</services>";
    ApplicationPackage applicationPackage = new MockApplicationPackage.Builder().withServices(servicesXml).build();
    VespaModel model = new VespaModel(new NullConfigModelRegistry(), new DeployState.Builder().applicationPackage(applicationPackage).properties(new DeployProperties.Builder().hostedVespa(true).build()).build(true));
    AbstractConfigProducerRoot modelRoot = model.getRoot();
    VipStatusConfig vipStatusConfig = modelRoot.getConfig(VipStatusConfig.class, "jdisc/component/status.html-status-handler");
    assertTrue(vipStatusConfig.accessdisk());
    assertEquals(ContainerModelBuilder.HOSTED_VESPA_STATUS_FILE, vipStatusConfig.statusfile());
}
Also used : NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) AbstractConfigProducerRoot(com.yahoo.config.model.producer.AbstractConfigProducerRoot) VespaModel(com.yahoo.vespa.model.VespaModel) DeployProperties(com.yahoo.config.model.deploy.DeployProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) VipStatusConfig(com.yahoo.container.core.VipStatusConfig) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) MockApplicationPackage(com.yahoo.config.model.test.MockApplicationPackage) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest) Test(org.junit.Test)

Example 4 with VipStatusConfig

use of com.yahoo.container.core.VipStatusConfig in project vespa by vespa-engine.

the class VipStatusHandlerTestCase method testFileNotFound.

@Test
public final void testFileNotFound() {
    final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true).statusfile("/VipStatusHandlerTestCaseFileThatReallyReallyShouldNotExist").noSearchBackendsImpliesOutOfService(false));
    final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
    final NotFoundResponseHandler responseHandler = new NotFoundResponseHandler();
    final HttpRequest request = createRequest();
    final BufferedContentChannel requestContent = createChannel();
    handler.handleRequest(request, requestContent, responseHandler);
    final ByteBuffer b = responseHandler.channel.read();
    final byte[] asBytes = new byte[b.remaining()];
    b.get(asBytes);
    assertEquals(VipStatusHandler.StatusResponse.COULD_NOT_FIND_STATUS_FILE, Utf8.toString(asBytes));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) VipStatusConfig(com.yahoo.container.core.VipStatusConfig) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with VipStatusConfig

use of com.yahoo.container.core.VipStatusConfig in project vespa by vespa-engine.

the class VipStatusHandlerTestCase method testHandleRequest.

@Test
public final void testHandleRequest() {
    final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false).noSearchBackendsImpliesOutOfService(false));
    final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
    final MockResponseHandler responseHandler = new MockResponseHandler();
    final HttpRequest request = createRequest();
    final BufferedContentChannel requestContent = createChannel();
    handler.handleRequest(request, requestContent, responseHandler);
    final ByteBuffer b = responseHandler.channel.read();
    final byte[] asBytes = new byte[b.remaining()];
    b.get(asBytes);
    assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) VipStatusConfig(com.yahoo.container.core.VipStatusConfig) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

VipStatusConfig (com.yahoo.container.core.VipStatusConfig)5 Test (org.junit.Test)5 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)4 HttpRequest (com.yahoo.jdisc.http.HttpRequest)4 ByteBuffer (java.nio.ByteBuffer)4 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 DeployProperties (com.yahoo.config.model.deploy.DeployProperties)1 AbstractConfigProducerRoot (com.yahoo.config.model.producer.AbstractConfigProducerRoot)1 MockApplicationPackage (com.yahoo.config.model.test.MockApplicationPackage)1 VespaModel (com.yahoo.vespa.model.VespaModel)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1