Search in sources :

Example 1 with PluggableService

use of com.cloud.utils.component.PluggableService in project cloudstack by apache.

the class ApiDiscoveryServiceImpl method start.

@Override
public boolean start() {
    if (s_apiNameDiscoveryResponseMap == null) {
        long startTime = System.nanoTime();
        s_apiNameDiscoveryResponseMap = new HashMap<String, ApiDiscoveryResponse>();
        Set<Class<?>> cmdClasses = new LinkedHashSet<Class<?>>();
        for (PluggableService service : _services) {
            s_logger.debug(String.format("getting api commands of service: %s", service.getClass().getName()));
            cmdClasses.addAll(service.getCommands());
        }
        cmdClasses.addAll(this.getCommands());
        cacheResponseMap(cmdClasses);
        long endTime = System.nanoTime();
        s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms");
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PluggableService(com.cloud.utils.component.PluggableService) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse)

Example 2 with PluggableService

use of com.cloud.utils.component.PluggableService in project cloudstack by apache.

the class ApiServer method start.

@Override
public boolean start() {
    Security.addProvider(new BouncyCastleProvider());
    // api port, null by default
    Integer apiPort = IntegrationAPIPort.value();
    final Long snapshotLimit = ConcurrentSnapshotsThresholdPerHost.value();
    if (snapshotLimit == null || snapshotLimit.longValue() <= 0) {
        s_logger.debug("Global concurrent snapshot config parameter " + ConcurrentSnapshotsThresholdPerHost.value() + " is less or equal 0; defaulting to unlimited");
    } else {
        dispatcher.setCreateSnapshotQueueSizeLimit(snapshotLimit);
    }
    final Long migrationLimit = VolumeApiService.ConcurrentMigrationsThresholdPerDatastore.value();
    if (migrationLimit == null || migrationLimit.longValue() <= 0) {
        s_logger.debug("Global concurrent migration config parameter " + VolumeApiService.ConcurrentMigrationsThresholdPerDatastore.value() + " is less or equal 0; defaulting to unlimited");
    } else {
        dispatcher.setMigrateQueueSizeLimit(migrationLimit);
    }
    final Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
    for (final PluggableService pluggableService : pluggableServices) {
        cmdClasses.addAll(pluggableService.getCommands());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Discovered plugin " + pluggableService.getClass().getSimpleName());
        }
    }
    for (final Class<?> cmdClass : cmdClasses) {
        final APICommand at = cmdClass.getAnnotation(APICommand.class);
        if (at == null) {
            throw new CloudRuntimeException(String.format("%s is claimed as a API command, but it doesn't have @APICommand annotation", cmdClass.getName()));
        }
        String apiName = at.name();
        List<Class<?>> apiCmdList = s_apiNameCmdClassMap.get(apiName);
        if (apiCmdList == null) {
            apiCmdList = new ArrayList<Class<?>>();
            s_apiNameCmdClassMap.put(apiName, apiCmdList);
        }
        apiCmdList.add(cmdClass);
    }
    setEncodeApiResponse(EncodeApiResponse.value());
    if (apiPort != null) {
        final ListenerThread listenerThread = new ListenerThread(this, apiPort);
        listenerThread.start();
    }
    return true;
}
Also used : PluggableService(com.cloud.utils.component.PluggableService) APICommand(org.apache.cloudstack.api.APICommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) HashSet(java.util.HashSet)

Example 3 with PluggableService

use of com.cloud.utils.component.PluggableService in project cloudstack by apache.

the class AccountManagerImpl method start.

@Override
public boolean start() {
    if (apiNameList == null) {
        long startTime = System.nanoTime();
        apiNameList = new ArrayList<String>();
        Set<Class<?>> cmdClasses = new LinkedHashSet<Class<?>>();
        for (PluggableService service : services) {
            s_logger.debug(String.format("getting api commands of service: %s", service.getClass().getName()));
            cmdClasses.addAll(service.getCommands());
        }
        apiNameList = createApiNameList(cmdClasses);
        long endTime = System.nanoTime();
        s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms");
    }
    _executor.scheduleAtFixedRate(new AccountCleanupTask(), _cleanupInterval, _cleanupInterval, TimeUnit.SECONDS);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PluggableService(com.cloud.utils.component.PluggableService)

Example 4 with PluggableService

use of com.cloud.utils.component.PluggableService in project cloudstack by apache.

the class RoleBasedAPIAccessChecker method start.

@Override
public boolean start() {
    for (RoleType role : RoleType.values()) {
        Long policyId = getDefaultPolicyId(role);
        if (policyId != null) {
            _iamSrv.resetIAMPolicy(policyId);
        }
    }
    // add the system-domain capability
    _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_ADMIN + 1), null, null, null, "SystemCapability", null, Permission.Allow, false);
    _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), null, null, null, "DomainCapability", null, Permission.Allow, false);
    _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN + 1), null, null, null, "DomainResourceCapability", null, Permission.Allow, false);
    // add permissions for public templates
    List<VMTemplateVO> pTmplts = _templateDao.listByPublic();
    for (VMTemplateVO tmpl : pTmplts) {
        _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_ADMIN + 1), VirtualMachineTemplate.class.getSimpleName(), PermissionScope.RESOURCE.toString(), tmpl.getId(), "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
        _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), VirtualMachineTemplate.class.getSimpleName(), PermissionScope.RESOURCE.toString(), tmpl.getId(), "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
        _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_NORMAL + 1), VirtualMachineTemplate.class.getSimpleName(), PermissionScope.RESOURCE.toString(), tmpl.getId(), "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
    }
    for (PluggableService service : _services) {
        for (Class<?> cmdClass : service.getCommands()) {
            APICommand command = cmdClass.getAnnotation(APICommand.class);
            if (!commandsPropertiesOverrides.contains(command.name())) {
                for (RoleType role : command.authorized()) {
                    addDefaultAclPolicyPermission(command.name(), cmdClass, role);
                }
            }
        }
    }
    for (String apiName : commandsPropertiesOverrides) {
        Class<?> cmdClass = _apiServer.getCmdClass(apiName);
        for (RoleType role : RoleType.values()) {
            if (commandsPropertiesRoleBasedApisMap.get(role).contains(apiName)) {
                // insert permission for this role for this api
                addDefaultAclPolicyPermission(apiName, cmdClass, role);
            }
        }
    }
    return super.start();
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) RoleType(org.apache.cloudstack.acl.RoleType) VMTemplateVO(com.cloud.storage.VMTemplateVO) PluggableService(com.cloud.utils.component.PluggableService) APICommand(org.apache.cloudstack.api.APICommand)

Example 5 with PluggableService

use of com.cloud.utils.component.PluggableService in project cosmic by MissionCriticalCloud.

the class ApiServer method start.

@Override
public boolean start() {
    // api port, null by default
    Integer apiPort = null;
    final SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
    sc.addAnd("name", SearchCriteria.Op.EQ, Config.IntegrationAPIPort.key());
    final List<ConfigurationVO> values = _configDao.search(sc, null);
    if ((values != null) && (values.size() > 0)) {
        final ConfigurationVO apiPortConfig = values.get(0);
        if (apiPortConfig.getValue() != null) {
            apiPort = Integer.parseInt(apiPortConfig.getValue());
        }
    }
    final Map<String, String> configs = _configDao.getConfiguration();
    final String strSnapshotLimit = configs.get(Config.ConcurrentSnapshotsThresholdPerHost.key());
    if (strSnapshotLimit != null) {
        final Long snapshotLimit = NumbersUtil.parseLong(strSnapshotLimit, 1L);
        if (snapshotLimit.longValue() <= 0) {
            s_logger.debug("Global config parameter " + Config.ConcurrentSnapshotsThresholdPerHost.toString() + " is less or equal 0; defaulting to unlimited");
        } else {
            _dispatcher.setCreateSnapshotQueueSizeLimit(snapshotLimit);
        }
    }
    final Set<Class<?>> cmdClasses = new HashSet<>();
    for (final PluggableService pluggableService : _pluggableServices) {
        cmdClasses.addAll(pluggableService.getCommands());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Discovered plugin " + pluggableService.getClass().getSimpleName());
        }
    }
    for (final Class<?> cmdClass : cmdClasses) {
        final APICommand at = cmdClass.getAnnotation(APICommand.class);
        if (at == null) {
            throw new CloudRuntimeException(String.format("%s is claimed as a API command, but it doesn't have @APICommand annotation", cmdClass.getName()));
        }
        final String apiName = at.name();
        List<Class<?>> apiCmdList = s_apiNameCmdClassMap.get(apiName);
        if (apiCmdList == null) {
            apiCmdList = new ArrayList<>();
            s_apiNameCmdClassMap.put(apiName, apiCmdList);
        }
        apiCmdList.add(cmdClass);
    }
    setEncodeApiResponse(Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key())));
    final String jsonType = _configDao.getValue(Config.JSONDefaultContentType.key());
    if (jsonType != null) {
        s_jsonContentType = jsonType;
    }
    final Boolean enableSecureSessionCookie = Boolean.valueOf(_configDao.getValue(Config.EnableSecureSessionCookie.key()));
    if (enableSecureSessionCookie != null) {
        s_enableSecureCookie = enableSecureSessionCookie;
    }
    if (apiPort != null) {
        final ListenerThread listenerThread = new ListenerThread(this, apiPort);
        listenerThread.start();
    }
    return true;
}
Also used : PluggableService(com.cloud.utils.component.PluggableService) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HashSet(java.util.HashSet)

Aggregations

PluggableService (com.cloud.utils.component.PluggableService)6 HashSet (java.util.HashSet)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 LinkedHashSet (java.util.LinkedHashSet)2 APICommand (org.apache.cloudstack.api.APICommand)2 ConfigurationVO (com.cloud.framework.config.impl.ConfigurationVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)1 RoleType (org.apache.cloudstack.acl.RoleType)1 ApiDiscoveryResponse (org.apache.cloudstack.api.response.ApiDiscoveryResponse)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1