static String getServiceName(Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ServiceName) { return ((ServiceName) annotation).value(); } } return null; }
@Produces @ServiceName("ZOOKEEPER") public String create(@New ZooKeeperServerConfig serverConfig) throws IOException, InterruptedException { String providedUrl = Systems.getEnvVarOrSystemProperty("ZOOKEEPER_URL", ""); if (Strings.isNullOrEmpty(providedUrl)) { ZooKeeperServerFactory factory = new ZooKeeperServerFactory(serverConfig); return factory.getZooKeeperUrl(); } else { return providedUrl; } } }
@ServiceName(HUBOT_SERVICE_NAME) private Instance<String> hubotUrlHolder;
@Produces @Singleton public CuratorFramework create(@ServiceName("ZOOKEEPER") String url, @New CuratorConfig config) throws IOException, InterruptedException { LOG.info("Connecting to ZooKeeper URL: {}", url); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(url) .connectionTimeoutMs(config.getConnectionTimeOut()) .sessionTimeoutMs(config.getSessionTimeout()) .retryPolicy(new RetryNTimes(config.getRetryMax(), config.getRetryInterval())); if (!Strings.isNullOrBlank(config.getPassword())) { byte[] auth = (DEFAULT_AUTH_USER + ":" + PasswordEncoder.decode(config.getPassword())).getBytes(); builder = builder.authorization(DEFAULT_AUTH_SCHEME, auth); } CuratorFramework curatorFramework = builder.build(); curatorFramework.start(); return curatorFramework; }
private boolean qualifies(Service s, Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ServiceName) { String id = ((ServiceName) annotation).value(); return id.equals(s.getId()); } } return false; } }
Session session; @ServiceName("zipkin") @ArquillianResource Service service;
private static void resolveServicesOffline( Object bean, List<Field> serverNameFields, JsonObject env) throws KubernetesClientException { serverNameFields.forEach( serviceNameField -> { final ServiceName serviceNameAnnotation = serviceNameField.getAnnotation(ServiceName.class); final String serviceName = serviceNameAnnotation.value(); final boolean withLabel = serviceNameField.isAnnotationPresent(WithLabel.class); final boolean withLabels = serviceNameField.isAnnotationPresent(WithLabels.class); if (isServiceNameOnly(withLabel, withLabels)) { resolveOfflineByServiceName(bean, env, serviceNameField, serviceName); } else { resolveOfflineServiceByLabelOnly(bean, env, serviceNameField, withLabel, withLabels); } }); }
@Inject public KubernetesHubotNotifier(HubotNotifier notifier, @External @Protocol("http") @ServiceName("fabric8") String consoleLink, @ConfigProperty(name = "HUBOT_KUBERNETES_ROOM", defaultValue = DEFAULT_ROOM_EXPRESSION) String roomExpression) throws Exception { this.notifier = notifier;
private static void findServiceEntryAndSetValue( Object bean, List<Field> serverNameFields, JsonObject env, KubernetesClient client) throws KubernetesClientException { Objects.requireNonNull(client, "no client available"); serverNameFields.forEach( serviceNameField -> { final ServiceName serviceNameAnnotation = serviceNameField.getAnnotation(ServiceName.class); final String serviceName = serviceNameAnnotation.value(); final boolean withLabel = serviceNameField.isAnnotationPresent(WithLabel.class); final boolean withLabels = serviceNameField.isAnnotationPresent(WithLabels.class); if (isServiceNameOnly(withLabel, withLabels)) { resolveByServiceName(bean, env, client, serviceNameField, serviceName); } else { resolveServiceByLabelOnly(bean, env, client, serviceNameField, withLabel, withLabels); } }); }