static String getServiceName(Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ServiceName) { return ((ServiceName) annotation).value(); } } return null; }
static String getReplicationControllerName(Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ReplicationControllerName) { return ((ReplicationControllerName) annotation).value(); } } return null; }
static String getPodName(Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof PodName) { return ((PodName) annotation).value(); } } return null; }
static Map<String, String> getLabels(Annotation... qualifiers) { HashMap<String, String> rc = new HashMap<String, String>(); for (Annotation annotation : qualifiers) { if (annotation instanceof WithLabel) { WithLabel l = (WithLabel) annotation; rc.put(l.name(), l.value()); } else if (annotation instanceof WithLabels) { WithLabels ls = (WithLabels) annotation; for (WithLabel l : ls.value()) { rc.put(l.name(), l.value()); } } } return rc; } }
@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;
@Protocol("http") @ServiceName(HUBOT_SERVICE_NAME) private Instance<String> hubotUrlHolder;
@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; } } }
/** * Implements a Git collector of commit metrics for the git repositories for BuildConfig objects */ @ApplicationScoped @Eager public class GitCollector { private final GitBuildConfigProcessor processor; private final BuildConfigCollectors collectors; private final BuildConfigWatcher watcher; /** * Note this constructor is only added to help CDI work with the {@link Eager} extension */ public GitCollector() throws Exception { this("gitCollectorWorkDir", 60000, 100, null); } @Inject public GitCollector(@ConfigProperty(name = "GIT_COLLECTOR_WORK_DIRECTORY", defaultValue = "gitCollectorWorkDir") String cloneFolder, @ConfigProperty(name = "GIT_COLLECTOR_SLEEP_PERIOD_MILLIS", defaultValue = "60000") long sleepPeriodMillis, @ConfigProperty(name = "GIT_COLLECTOR_COMMIT_LIMIT_PER_POLL", defaultValue = "100") int commitLimitPerPoll, GitElasticsearchClient elasticsearchClient) throws Exception { this.processor = new GitBuildConfigProcessor(elasticsearchClient, new File(cloneFolder), commitLimitPerPoll); this.collectors = new BuildConfigCollectors(processor, sleepPeriodMillis); this.watcher = new BuildConfigWatcher(collectors); } }
private static String resolveOfflineServiceWithPortName( JsonObject env, Field serviceNameField, String serviceEntry) { final PortName portNameAnnotation = serviceNameField.getAnnotation(PortName.class); final String portName = resolveProperty(env, portNameAnnotation.value()); final String portValue = ConfigurationUtil.getStringConfiguration(env, portName, null); return buildOfflineServiceHostString(serviceEntry, portValue, null); }
private static Map<String, String> getLabelsFromAnnotation( JsonObject env, Field serviceNameField, boolean withLabel, boolean withLabels) { final Map<String, String> labels = new HashMap<>(); if (withLabel) { final WithLabel wl = serviceNameField.getAnnotation(WithLabel.class); labels.put(resolveProperty(env, wl.name()), resolveProperty(env, wl.value())); } if (withLabels) { final WithLabels wls = serviceNameField.getAnnotation(WithLabels.class); labels.putAll( Stream.of(wls.value()) .collect( Collectors.toMap( wl -> resolveProperty(env, wl.name()), wl -> resolveProperty(env, wl.value())))); } return labels; }
@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; } }
@Eager public class KubernetesHubotNotifier { public static final String DEFAULT_ROOM_EXPRESSION = "#fabric8_${namespace}";
private boolean qualifies(ReplicationController r, Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ReplicationControllerName) { String id = ((ReplicationControllerName) annotation).value(); return id.equals(r.getId()); } } return false; } }
private static String resolveServiceWithPortName( JsonObject env, Field serviceNameField, String clusterIP, List<ServicePort> ports) { String hostString = null; final PortName portNameAnnotation = serviceNameField.getAnnotation(PortName.class); final String portName = resolveProperty(env, portNameAnnotation.value()); final Optional<ServicePort> portMatch = findPortByName(ports, portName); if (portMatch.isPresent()) { final ServicePort port = portMatch.get(); final String protocol = port.getProtocol(); // TODO check out how http can get resolved hostString = buildServiceHostString(clusterIP, port, null); } return hostString; }
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); } }); }
@Eager public class ChaosMonkey { public static final String DEFAULT_ROOM_EXPRESSION = "#fabric8_${namespace}";
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); } }); }