<commit_before>package io.subutai.core.hubmanager.impl;


import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.core.Response;

import org.bouncycastle.openpgp.PGPException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.commons.io.FileUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.http.HttpStatus;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.subutai.common.dao.DaoManager;
import io.subutai.core.environment.api.EnvironmentManager;
import io.subutai.core.executor.api.CommandExecutor;
import io.subutai.core.hubmanager.api.HubPluginException;
import io.subutai.core.hubmanager.api.Integration;
import io.subutai.core.hubmanager.api.StateLinkProccessor;
import io.subutai.core.hubmanager.api.dao.ConfigDataService;
import io.subutai.core.hubmanager.api.model.Config;
import io.subutai.core.hubmanager.impl.appscale.AppScaleManager;
import io.subutai.core.hubmanager.impl.appscale.AppScaleProcessor;
import io.subutai.core.hubmanager.impl.dao.ConfigDataServiceImpl;
import io.subutai.core.hubmanager.impl.proccessors.ContainerEventProcessor;
import io.subutai.core.hubmanager.impl.proccessors.EnvironmentUserHelper;
import io.subutai.core.hubmanager.impl.proccessors.HeartbeatProcessor;
import io.subutai.core.hubmanager.impl.proccessors.HubEnvironmentProccessor;
import io.subutai.core.hubmanager.impl.proccessors.HubLoggerProcessor;
import io.subutai.core.hubmanager.impl.proccessors.ResourceHostConfProcessor;
import io.subutai.core.hubmanager.impl.proccessors.ResourceHostMonitorProcessor;
import io.subutai.core.hubmanager.impl.proccessors.SystemConfProcessor;
import io.subutai.core.hubmanager.impl.proccessors.VehsProccessor;
import io.subutai.core.hubmanager.impl.tunnel.TunnelProcessor;
import io.subutai.core.identity.api.IdentityManager;
import io.subutai.core.metric.api.Monitor;
import io.subutai.core.network.api.NetworkManager;
import io.subutai.core.peer.api.PeerManager;
import io.subutai.core.security.api.SecurityManager;
import io.subutai.hub.share.dto.PeerDto;
import io.subutai.hub.share.dto.SystemConfDto;
import io.subutai.hub.share.dto.product.ProductsDto;
import io.subutai.hub.share.json.JsonUtil;


//TODO close web clients and responses
public class IntegrationImpl implements Integration
{
    private static final long TIME_15_MINUTES = 900;

    private static final Logger LOG = LoggerFactory.getLogger( IntegrationImpl.class );

    private SecurityManager securityManager;

    private EnvironmentManager environmentManager;

    private PeerManager peerManager;

    private ConfigManager configManager;

    private CommandExecutor commandExecutor;

    private ScheduledExecutorService hearbeatExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService resourceHostConfExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService resourceHostMonitorExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService hubLoggerExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService containerEventExecutor = Executors.newSingleThreadScheduledExecutor();

    private HeartbeatProcessor heartbeatProcessor;

    private ResourceHostConfProcessor resourceHostConfProcessor;

    private SystemConfProcessor systemConfProcessor;

    private ResourceHostMonitorProcessor resourceHostMonitorProcessor;

    private HubLoggerProcessor hubLoggerProcessor;

    private DaoManager daoManager;

    private ConfigDataService configDataService;

    private Monitor monitor;

    private IdentityManager identityManager;

    private HubEnvironmentManager hubEnvironmentManager;

    private NetworkManager networkManager;

    private ContainerEventProcessor containerEventProcessor;

    private ScheduledExecutorService sumChecker = Executors.newSingleThreadScheduledExecutor();

    private String checksum = "";


    public IntegrationImpl( DaoManager daoManager )
    {
        this.daoManager = daoManager;
    }


    public void init()
    {
        try
        {
            configDataService = new ConfigDataServiceImpl( daoManager );

            configManager = new ConfigManager( securityManager, peerManager, configDataService, identityManager );

            hubEnvironmentManager =
                    new HubEnvironmentManager( environmentManager, configManager, peerManager, identityManager,
                            networkManager );

            heartbeatProcessor = new HeartbeatProcessor( this, configManager );

            resourceHostConfProcessor = new ResourceHostConfProcessor( this, peerManager, configManager, monitor );

            hubLoggerProcessor = new HubLoggerProcessor( configManager, this );

            resourceHostMonitorProcessor =
                    new ResourceHostMonitorProcessor( this, peerManager, configManager, monitor );

            StateLinkProccessor systemConfProcessor = new SystemConfProcessor( configManager );

            EnvironmentUserHelper environmentUserHelper =
                    new EnvironmentUserHelper( configManager, identityManager, configDataService, environmentManager );

            StateLinkProccessor hubEnvironmentProccessor =
                    new HubEnvironmentProccessor( hubEnvironmentManager, configManager, peerManager, identityManager,
                            commandExecutor, environmentUserHelper );

            StateLinkProccessor vehsProccessor =
                    new VehsProccessor( hubEnvironmentManager, configManager, peerManager, commandExecutor,
                            environmentUserHelper );

            StateLinkProccessor tunnelProcessor = new TunnelProcessor( peerManager, configManager );

            heartbeatProcessor.addProccessor( vehsProccessor );
            heartbeatProcessor.addProccessor( hubEnvironmentProccessor );
            heartbeatProcessor.addProccessor( systemConfProcessor );

            AppScaleProcessor appScaleProcessor =
                    new AppScaleProcessor( configManager, new AppScaleManager( peerManager ) );

            heartbeatProcessor.addProccessor( appScaleProcessor );

            heartbeatProcessor.addProccessor( tunnelProcessor );

            hearbeatExecutorService.scheduleWithFixedDelay( heartbeatProcessor, 10, 60, TimeUnit.SECONDS );

            resourceHostConfExecutorService
                    .scheduleWithFixedDelay( resourceHostConfProcessor, 20, TIME_15_MINUTES, TimeUnit.SECONDS );

            resourceHostMonitorExecutorService
                    .scheduleWithFixedDelay( resourceHostMonitorProcessor, 30, 300, TimeUnit.SECONDS );

            containerEventProcessor = new ContainerEventProcessor( this, configManager, peerManager );

            containerEventExecutor
                    .scheduleWithFixedDelay( containerEventProcessor, 30, TIME_15_MINUTES, TimeUnit.SECONDS );<commit_msg>Fixed product installation via HUB<commit_after>package io.subutai.core.hubmanager.impl;


import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.core.Response;

import org.bouncycastle.openpgp.PGPException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.commons.io.FileUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.http.HttpStatus;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.subutai.common.dao.DaoManager;
import io.subutai.core.environment.api.EnvironmentManager;
import io.subutai.core.executor.api.CommandExecutor;
import io.subutai.core.hubmanager.api.HubPluginException;
import io.subutai.core.hubmanager.api.Integration;
import io.subutai.core.hubmanager.api.StateLinkProccessor;
import io.subutai.core.hubmanager.api.dao.ConfigDataService;
import io.subutai.core.hubmanager.api.model.Config;
import io.subutai.core.hubmanager.impl.appscale.AppScaleManager;
import io.subutai.core.hubmanager.impl.appscale.AppScaleProcessor;
import io.subutai.core.hubmanager.impl.dao.ConfigDataServiceImpl;
import io.subutai.core.hubmanager.impl.proccessors.ContainerEventProcessor;
import io.subutai.core.hubmanager.impl.proccessors.EnvironmentUserHelper;
import io.subutai.core.hubmanager.impl.proccessors.HeartbeatProcessor;
import io.subutai.core.hubmanager.impl.proccessors.HubEnvironmentProccessor;
import io.subutai.core.hubmanager.impl.proccessors.HubLoggerProcessor;
import io.subutai.core.hubmanager.impl.proccessors.ProductProccessor;
import io.subutai.core.hubmanager.impl.proccessors.ResourceHostConfProcessor;
import io.subutai.core.hubmanager.impl.proccessors.ResourceHostMonitorProcessor;
import io.subutai.core.hubmanager.impl.proccessors.SystemConfProcessor;
import io.subutai.core.hubmanager.impl.proccessors.VehsProccessor;
import io.subutai.core.hubmanager.impl.tunnel.TunnelProcessor;
import io.subutai.core.identity.api.IdentityManager;
import io.subutai.core.metric.api.Monitor;
import io.subutai.core.network.api.NetworkManager;
import io.subutai.core.peer.api.PeerManager;
import io.subutai.core.security.api.SecurityManager;
import io.subutai.hub.share.dto.PeerDto;
import io.subutai.hub.share.dto.SystemConfDto;
import io.subutai.hub.share.dto.product.ProductsDto;
import io.subutai.hub.share.json.JsonUtil;


//TODO close web clients and responses
public class IntegrationImpl implements Integration
{
    private static final long TIME_15_MINUTES = 900;

    private static final Logger LOG = LoggerFactory.getLogger( IntegrationImpl.class );

    private SecurityManager securityManager;

    private EnvironmentManager environmentManager;

    private PeerManager peerManager;

    private ConfigManager configManager;

    private CommandExecutor commandExecutor;

    private ScheduledExecutorService hearbeatExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService resourceHostConfExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService resourceHostMonitorExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService hubLoggerExecutorService = Executors.newSingleThreadScheduledExecutor();

    private ScheduledExecutorService containerEventExecutor = Executors.newSingleThreadScheduledExecutor();

    private HeartbeatProcessor heartbeatProcessor;

    private ResourceHostConfProcessor resourceHostConfProcessor;

    private SystemConfProcessor systemConfProcessor;

    private ResourceHostMonitorProcessor resourceHostMonitorProcessor;

    private HubLoggerProcessor hubLoggerProcessor;

    private DaoManager daoManager;

    private ConfigDataService configDataService;

    private Monitor monitor;

    private IdentityManager identityManager;

    private HubEnvironmentManager hubEnvironmentManager;

    private NetworkManager networkManager;

    private ContainerEventProcessor containerEventProcessor;

    private ProductProccessor productProccessor;

    private ScheduledExecutorService sumChecker = Executors.newSingleThreadScheduledExecutor();

    private String checksum = "";


    public IntegrationImpl( DaoManager daoManager )
    {
        this.daoManager = daoManager;
    }


    public void init()
    {
        try
        {
            configDataService = new ConfigDataServiceImpl( daoManager );

            configManager = new ConfigManager( securityManager, peerManager, configDataService, identityManager );

            hubEnvironmentManager =
                    new HubEnvironmentManager( environmentManager, configManager, peerManager, identityManager,
                            networkManager );

            heartbeatProcessor = new HeartbeatProcessor( this, configManager );

            resourceHostConfProcessor = new ResourceHostConfProcessor( this, peerManager, configManager, monitor );

            hubLoggerProcessor = new HubLoggerProcessor( configManager, this );

            resourceHostMonitorProcessor =
                    new ResourceHostMonitorProcessor( this, peerManager, configManager, monitor );

            productProccessor = new ProductProccessor( configManager );

            StateLinkProccessor systemConfProcessor = new SystemConfProcessor( configManager );

            EnvironmentUserHelper environmentUserHelper =
                    new EnvironmentUserHelper( configManager, identityManager, configDataService, environmentManager );

            StateLinkProccessor hubEnvironmentProccessor =
                    new HubEnvironmentProccessor( hubEnvironmentManager, configManager, peerManager, identityManager,
                            commandExecutor, environmentUserHelper );

            StateLinkProccessor vehsProccessor =
                    new VehsProccessor( hubEnvironmentManager, configManager, peerManager, commandExecutor,
                            environmentUserHelper );

            StateLinkProccessor tunnelProcessor = new TunnelProcessor( peerManager, configManager );

            heartbeatProcessor.addProccessor( vehsProccessor );
            heartbeatProcessor.addProccessor( hubEnvironmentProccessor );
            heartbeatProcessor.addProccessor( systemConfProcessor );
            heartbeatProcessor.addProccessor( productProccessor );

            AppScaleProcessor appScaleProcessor =
                    new AppScaleProcessor( configManager, new AppScaleManager( peerManager ) );

            heartbeatProcessor.addProccessor( appScaleProcessor );

            heartbeatProcessor.addProccessor( tunnelProcessor );

            hearbeatExecutorService.scheduleWithFixedDelay( heartbeatProcessor, 10, 60, TimeUnit.SECONDS );

            resourceHostConfExecutorService
                    .scheduleWithFixedDelay( resourceHostConfProcessor, 20, TIME_15_MINUTES, TimeUnit.SECONDS );

            resourceHostMonitorExecutorService
                    .scheduleWithFixedDelay( resourceHostMonitorProcessor, 30, 300, TimeUnit.SECONDS );

            containerEventProcessor = new ContainerEventProcessor( this, configManager, peerManager );

            containerEventExecutor
                    .scheduleWithFixedDelay( containerEventProcessor, 30, TIME_15_MINUTES, TimeUnit.SECONDS );
{'fraction_non_alphanumeric': 0.06743175776437788, 'fraction_numerical': 0.0031122349737405172, 'mean_word_length': 4.340720221606648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5018246', 'n_tokens_mistral': 4026, 'n_tokens_neox': 3839, 'n_words': 719}