CloudWatchValidator extends Validator { @Override public void validate(VespaModel model, DeployState deployState) { if (!deployState.isHosted()) return; if (deployState.zone().system().isPublic()) return; if (model.getAdmin().getApplicationType() != ConfigModelContext.ApplicationType.DEFAULT) return; var offendingConsumers = model.getAdmin().getUserMetrics().getConsumers().values().stream() .filter(consumer -> !consumer.cloudWatches().isEmpty()) .collect(toList()); if (! offendingConsumers.isEmpty()) { throw new IllegalArgumentException("CloudWatch cannot be set up for non-public hosted Vespa and must " + "be removed for consumers: " + consumerIds(offendingConsumers)); } }  @Override void validate(VespaModel model, DeployState deployState);  }
@Test public void cloudwatch_in_public_zones_passes_validation() throws IOException, SAXException { DeployState deployState = deployState(servicesWithCloudwatch(), true, true); VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState); new CloudWatchValidator().validate(model, deployState); }
@Test public void cloudwatch_passes_validation_for_self_hosted_vespa() throws IOException, SAXException { DeployState deployState = deployState(servicesWithCloudwatch(), false, false); VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState); new CloudWatchValidator().validate(model, deployState); }
@Test public void cloudwatch_in_non_public_zones_fails_validation() throws IOException, SAXException { exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage( "CloudWatch cannot be set up for non-public hosted Vespa and must be removed for consumers: [cloudwatch-consumer]"); DeployState deployState = deployState(servicesWithCloudwatch(), true, false); VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState); new CloudWatchValidator().validate(model, deployState); }