Search in sources :

Example 11 with Instance

use of javax.enterprise.inject.Instance in project stackgres by ongres.

the class DbOpsDeployedResourceScanner method getDeployedResources.

@Override
public List<HasMetadata> getDeployedResources(StackGresDbOps config) {
    try (KubernetesClient client = clientFactory.create()) {
        final Map<String, String> genericLabels = labelFactory.genericLabels(config);
        Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericLabels).list().getItems().stream());
        List<HasMetadata> deployedResources = inNamespace.filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresDbOps.KIND) && ownerReference.getName().equals(config.getMetadata().getName()) && ownerReference.getUid().equals(config.getMetadata().getUid()))).collect(Collectors.toUnmodifiableList());
        deployedResources.forEach(resource -> {
            Instance<DeployedResourceDecorator> decorator = decorators.select(new ReconciliationScopeLiteral(StackGresDbOps.class, resource.getKind()));
            if (decorator.isResolvable()) {
                decorator.get().decorate(resource);
            }
        });
        return deployedResources;
    }
}
Also used : KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ReconciliationOperations(io.stackgres.operator.conciliation.ReconciliationOperations) Role(io.fabric8.kubernetes.api.model.rbac.Role) Function(java.util.function.Function) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) Resource(io.fabric8.kubernetes.client.dsl.Resource) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator) Map(java.util.Map) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) Any(javax.enterprise.inject.Any) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Instance(javax.enterprise.inject.Instance) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DeployedResourcesScanner(io.stackgres.operator.conciliation.DeployedResourcesScanner) List(java.util.List) Stream(java.util.stream.Stream) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator)

Example 12 with Instance

use of javax.enterprise.inject.Instance in project stackgres by ongres.

the class BackupDeployedResourceScanner method getDeployedResources.

@Override
public List<HasMetadata> getDeployedResources(StackGresBackup config) {
    try (KubernetesClient client = clientFactory.create()) {
        final Map<String, String> genericLabels = labelFactory.genericLabels(config);
        Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericLabels).list().getItems().stream());
        List<HasMetadata> deployedResources = inNamespace.filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresBackup.KIND) && ownerReference.getName().equals(config.getMetadata().getName()) && ownerReference.getUid().equals(config.getMetadata().getUid()))).collect(Collectors.toUnmodifiableList());
        deployedResources.forEach(resource -> {
            Instance<DeployedResourceDecorator> decorator = decorators.select(new ReconciliationScopeLiteral(StackGresBackup.class, resource.getKind()));
            if (decorator.isResolvable()) {
                decorator.get().decorate(resource);
            }
        });
        return deployedResources;
    }
}
Also used : ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) LabelFactoryForBackup(io.stackgres.common.LabelFactoryForBackup) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) ReconciliationOperations(io.stackgres.operator.conciliation.ReconciliationOperations) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Inject(javax.inject.Inject) DeployedResourcesScanner(io.stackgres.operator.conciliation.DeployedResourcesScanner) List(java.util.List) Resource(io.fabric8.kubernetes.client.dsl.Resource) Stream(java.util.stream.Stream) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Any(javax.enterprise.inject.Any) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Instance(javax.enterprise.inject.Instance) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator)

Example 13 with Instance

use of javax.enterprise.inject.Instance in project quarkus by quarkusio.

the class InstanceBean method get.

@SuppressWarnings("unchecked")
@Override
public Instance<?> get(CreationalContext<Instance<?>> creationalContext) {
    // Obtain current IP to get the required type and qualifiers
    InjectionPoint ip = InjectionPointProvider.get();
    InstanceImpl<Instance<?>> instance = new InstanceImpl<Instance<?>>((InjectableBean<?>) ip.getBean(), ip.getType(), ip.getQualifiers(), (CreationalContextImpl<?>) creationalContext, Collections.EMPTY_SET, ip.getMember(), 0);
    CreationalContextImpl.addDependencyToParent((InjectableBean<Instance<?>>) ip.getBean(), instance, creationalContext);
    return instance;
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Instance(javax.enterprise.inject.Instance)

Example 14 with Instance

use of javax.enterprise.inject.Instance in project quarkus by quarkusio.

the class BuiltInBeansAreResolvableTest method testInstanceBean.

@SuppressWarnings({ "serial", "unchecked" })
@Test
public void testInstanceBean() {
    BeanManager bm = Arc.container().beanManager();
    // verify all selections have a backing bean
    Set<Bean<?>> instanceBeans = bm.getBeans(Instance.class);
    assertEquals(1, instanceBeans.size());
    Set<Bean<?>> typedInstanceBeans = bm.getBeans(new TypeLiteral<Instance<DummyBean>>() {
    }.getType());
    assertEquals(1, typedInstanceBeans.size());
    Set<Bean<?>> typedQualifiedInstanceBean = bm.getBeans(new TypeLiteral<Instance<DummyBean>>() {
    }.getType(), new DummyQualifier.Literal());
    assertEquals(1, typedQualifiedInstanceBean.size());
    InjectionPoint dummyIp = new InjectionPoint() {

        @Override
        public Type getType() {
            return new TypeLiteral<Instance<DummyBean>>() {
            }.getType();
        }

        @Override
        public Set<Annotation> getQualifiers() {
            return new HashSet<>();
        }

        @Override
        public Bean<?> getBean() {
            return null;
        }

        @Override
        public Member getMember() {
            return null;
        }

        @Override
        public Annotated getAnnotated() {
            return null;
        }

        @Override
        public boolean isDelegate() {
            return false;
        }

        @Override
        public boolean isTransient() {
            return false;
        }
    };
    InjectionPoint dummyIpWithQualifiers = new InjectionPoint() {

        @Override
        public Type getType() {
            return new TypeLiteral<Instance<DummyBean>>() {
            }.getType();
        }

        @Override
        public Set<Annotation> getQualifiers() {
            return new HashSet<>(Arrays.asList(Any.Literal.INSTANCE, new DummyQualifier.Literal()));
        }

        @Override
        public Bean<?> getBean() {
            return null;
        }

        @Override
        public Member getMember() {
            return null;
        }

        @Override
        public Annotated getAnnotated() {
            return null;
        }

        @Override
        public boolean isDelegate() {
            return false;
        }

        @Override
        public boolean isTransient() {
            return false;
        }
    };
    Instance<DummyBean> dummyInstance = (Instance<DummyBean>) bm.getInjectableReference(dummyIp, new CreationalContextImpl<>(null));
    // not resolvable, no qualifier
    assertFalse(dummyInstance.isResolvable());
    dummyInstance.select(new DummyQualifier.Literal()).get().ping();
    Instance<DummyBean> dummyInstanceWithQualifier = (Instance<DummyBean>) bm.getInjectableReference(dummyIpWithQualifiers, new CreationalContextImpl<>(null));
    // resolvable, qualifier is present
    assertTrue(dummyInstanceWithQualifier.isResolvable());
    dummyInstanceWithQualifier.get().ping();
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Instance(javax.enterprise.inject.Instance) CreationalContextImpl(io.quarkus.arc.impl.CreationalContextImpl) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean) TypeLiteral(javax.enterprise.util.TypeLiteral) TypeLiteral(javax.enterprise.util.TypeLiteral) AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) BeanManager(javax.enterprise.inject.spi.BeanManager) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 15 with Instance

use of javax.enterprise.inject.Instance in project openwebbeans by apache.

the class InstanceProducer method produce.

@Override
protected Instance<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Instance<T>> creationalContext) {
    CreationalContextImpl<Instance<T>> creationalContextImpl = null;
    try {
        InjectionPoint injectionPoint = null;
        if (creationalContext instanceof CreationalContextImpl) {
            creationalContextImpl = creationalContext;
        } else {
            InstanceBean<Object> instanceBean = webBeansContext.getWebBeansUtil().getInstanceBean();
            creationalContextImpl = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext, instanceBean);
        }
        injectionPoint = creationalContextImpl.getInjectionPoint();
        Set<Annotation> qualifiers;
        Type type;
        if (injectionPoint != null) {
            ParameterizedType injectedType = (ParameterizedType) injectionPoint.getType();
            qualifiers = injectionPoint.getQualifiers();
            type = injectedType.getActualTypeArguments()[0];
        } else {
            // an 'empty' directly resolved Instance always is for Default qualified Objects
            qualifiers = DefaultLiteral.SET;
            type = Object.class;
        }
        return new InstanceImpl<>(type, injectionPoint, webBeansContext, qualifiers.toArray(new Annotation[qualifiers.size()]));
    } finally {
        if (creationalContextImpl != null) {
            creationalContextImpl.removeInjectionPoint();
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Instance(javax.enterprise.inject.Instance) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) CreationalContextImpl(org.apache.webbeans.context.creational.CreationalContextImpl) InstanceImpl(org.apache.webbeans.inject.instance.InstanceImpl) Annotation(java.lang.annotation.Annotation)

Aggregations

Instance (javax.enterprise.inject.Instance)39 Test (org.junit.Test)14 List (java.util.List)10 Inject (javax.inject.Inject)10 ArrayList (java.util.ArrayList)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Map (java.util.Map)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)6 Annotation (java.lang.annotation.Annotation)5 Stream (java.util.stream.Stream)4 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Settings (com.artezio.arttime.config.Settings)3 Dl (eu.ggnet.dwoss.core.widget.Dl)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 JCommander (com.beust.jcommander.JCommander)2 ParameterException (com.beust.jcommander.ParameterException)2