Search in sources :

Example 1 with ApplicationMetaDataProvider

use of org.glassfish.api.deployment.ApplicationMetaDataProvider in project Payara by payara.

the class ApplicationLifecycle method loadDeployers.

private List<Deployer> loadDeployers(Map<Deployer, EngineInfo> containerInfosByDeployers, DeploymentContext context) throws IOException {
    final ActionReport report = context.getActionReport();
    final Map<Class, ApplicationMetaDataProvider> typeByProvider = getTypeByProvider();
    final Map<Class, Deployer> typeByDeployer = getTypeByDeployer(containerInfosByDeployers);
    final StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    for (Deployer deployer : containerInfosByDeployers.keySet()) {
        if (deployer.getMetaData() != null) {
            for (Class dependency : deployer.getMetaData().requires()) {
                if (!typeByDeployer.containsKey(dependency) && !typeByProvider.containsKey(dependency)) {
                    Service s = deployer.getClass().getAnnotation(Service.class);
                    String serviceName;
                    if (s != null && s.name() != null && s.name().length() > 0) {
                        serviceName = s.name();
                    } else {
                        serviceName = deployer.getClass().getSimpleName();
                    }
                    report.failure(logger, serviceName + " deployer requires " + dependency + " but no other deployer provides it", null);
                    return null;
                }
            }
        }
    }
    List<Deployer> orderedDeployers = new ArrayList<>();
    for (Map.Entry<Deployer, EngineInfo> entry : containerInfosByDeployers.entrySet()) {
        Deployer deployer = entry.getKey();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(FINE, "Keyed Deployer {0}", deployer.getClass());
        }
        DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, entry.getValue().getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE);
        loadDeployer(orderedDeployers, deployer, typeByDeployer, typeByProvider, context);
        span.close();
    }
    return orderedDeployers;
}
Also used : HotDeployService(fish.payara.nucleus.hotdeploy.HotDeployService) Service(org.jvnet.hk2.annotations.Service) PayaraExecutorService(fish.payara.nucleus.executorservice.PayaraExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ActionReport(org.glassfish.api.ActionReport) EngineInfo(org.glassfish.internal.data.EngineInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Collectors.toMap(java.util.stream.Collectors.toMap) ParameterMap(org.glassfish.api.admin.ParameterMap) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) Deployer(org.glassfish.api.deployment.Deployer)

Example 2 with ApplicationMetaDataProvider

use of org.glassfish.api.deployment.ApplicationMetaDataProvider in project Payara by payara.

the class ApplicationState method reloadApplicationMetaData.

private void reloadApplicationMetaData(DeploymentContext dc) throws IOException {
    Deployment deployment = habitat.getService(Deployment.class);
    Map<Class, ApplicationMetaDataProvider> typeByProvider = deployment.getTypeByProvider();
    for (Class requiredMetaDataClasse : this.requiredMetaDataClasses()) {
        ApplicationMetaDataProvider metaDataProvider = typeByProvider.get(requiredMetaDataClasse);
        metaDataProvider.load(dc);
    }
}
Also used : Deployment(org.glassfish.internal.deployment.Deployment) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider)

Example 3 with ApplicationMetaDataProvider

use of org.glassfish.api.deployment.ApplicationMetaDataProvider in project Payara by payara.

the class ApplicationLifecycle method getTypeByProvider.

public Map<Class, ApplicationMetaDataProvider> getTypeByProvider() {
    // in reality, there is single implementation of ApplicationMetadataProvider at this point.
    final Map<Class, ApplicationMetaDataProvider> typeByProvider = new HashMap<>();
    final List<ApplicationMetaDataProvider> providers = habitat.<ApplicationMetaDataProvider>getAllServices(ApplicationMetaDataProvider.class);
    for (ApplicationMetaDataProvider provider : providers) {
        if (provider.getMetaData() != null) {
            for (Class provided : provider.getMetaData().provides()) {
                typeByProvider.put(provided, provider);
            }
        }
    }
    // check if everything is provided.
    for (ApplicationMetaDataProvider provider : providers) {
        if (provider.getMetaData() != null) {
            for (Class dependency : provider.getMetaData().requires()) {
                if (!typeByProvider.containsKey(dependency)) {
                    // at this point, I only log problems, because it maybe that what I am deploying now
                    // will not require this application metadata.
                    logger.log(WARNING, KernelLoggerInfo.applicationMetaDataProvider, new Object[] { provider, dependency });
                }
            }
        }
    }
    return typeByProvider;
}
Also used : ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider)

Example 4 with ApplicationMetaDataProvider

use of org.glassfish.api.deployment.ApplicationMetaDataProvider in project Payara by payara.

the class ApplicationLifecycle method loadDeployer.

private void loadDeployer(List<Deployer> results, Deployer deployer, Map<Class, Deployer> typeByDeployer, Map<Class, ApplicationMetaDataProvider> typeByProvider, DeploymentContext dc) throws IOException {
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(dc);
    if (results.contains(deployer)) {
        return;
    }
    results.add(deployer);
    if (deployer.getMetaData() != null) {
        for (Class required : deployer.getMetaData().requires()) {
            if (dc.getModuleMetaData(required) != null) {
                continue;
            }
            if (typeByDeployer.containsKey(required)) {
                loadDeployer(results, typeByDeployer.get(required), typeByDeployer, typeByProvider, dc);
            } else {
                ApplicationMetaDataProvider provider = typeByProvider.get(required);
                if (provider == null) {
                    logger.log(SEVERE, KernelLoggerInfo.inconsistentLifecycleState, required);
                } else {
                    LinkedList<ApplicationMetaDataProvider> providers = new LinkedList<>();
                    addRecursively(providers, typeByProvider, provider);
                    for (ApplicationMetaDataProvider p : providers) {
                        // this actually loads all descriptors of the app.
                        try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.APPLICATION, null, DeploymentTracing.AppStage.LOAD, "DeploymentDescriptor")) {
                            dc.addModuleMetaData(p.load(dc));
                        }
                    }
                }
            }
        }
    }
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider)

Aggregations

ApplicationMetaDataProvider (org.glassfish.api.deployment.ApplicationMetaDataProvider)4 DeploymentSpan (org.glassfish.internal.deployment.analysis.DeploymentSpan)2 StructuredDeploymentTracing (org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing)2 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)1 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 ActionReport (org.glassfish.api.ActionReport)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 Deployer (org.glassfish.api.deployment.Deployer)1 EngineInfo (org.glassfish.internal.data.EngineInfo)1 Deployment (org.glassfish.internal.deployment.Deployment)1 Service (org.jvnet.hk2.annotations.Service)1