Search in sources :

Example 6 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class StoreQueryTableTestCase method test13.

@Test
public void test13() throws InterruptedException {
    log.info("Test13 - Test output attributes and its types for aggregation table");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "define aggregation StockTableAg " + "from StockStream " + "select symbol, price " + "group by symbol " + "aggregate every minutes ...year;";
    String storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, price ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute };
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
    storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, sum(price) as total";
    actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
    Attribute totalVolumeAttribute = new Attribute("total", Attribute.Type.DOUBLE);
    expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 7 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class ApiDAOImpl method initApiTypes.

static void initApiTypes() throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            if (!isApiTypesExist(connection)) {
                connection.setAutoCommit(false);
                addApiTypes(connection);
                connection.commit();
            }
        } catch (SQLException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding API types", e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding API types", e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 8 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method addServicesToEndpointList.

/**
 * For each service in {@code serviceList} list, methods are called to add endpoints of different types,
 * for each of service's ports
 *
 * @param serviceList filtered list of services
 */
private void addServicesToEndpointList(List<Service> serviceList, List<Endpoint> endpointList) throws MalformedURLException {
    for (Service service : serviceList) {
        // Set the parameters that does not change with the service port
        String serviceName = service.getMetadata().getName();
        String namespace = service.getMetadata().getNamespace();
        Map<String, String> labelsMap = service.getMetadata().getLabels();
        String labels = (labelsMap != null) ? labelsMap.toString() : "";
        ServiceSpec serviceSpec = service.getSpec();
        String serviceType = serviceSpec.getType();
        if (includeExternalNameTypeServices && EXTERNAL_NAME.equals(serviceType)) {
            // Since only a "ExternalName" type service can have an "externalName" (the alias in kube-dns)
            addExternalNameEndpoint(serviceName, serviceSpec.getExternalName(), namespace, labels, endpointList);
        }
        for (ServicePort servicePort : serviceSpec.getPorts()) {
            String protocol = servicePort.getName();
            if (APIMgtConstants.HTTP.equals(protocol) || APIMgtConstants.HTTPS.equals(protocol)) {
                int port = servicePort.getPort();
                if (includeClusterIP && !EXTERNAL_NAME.equals(serviceType)) {
                    // Since almost every service has a cluster IP, except for ExternalName type
                    addClusterIPEndpoint(serviceName, serviceSpec.getClusterIP(), port, protocol, namespace, labels, endpointList);
                }
                if (NODE_PORT.equals(serviceType) || LOAD_BALANCER.equals(serviceType)) {
                    // Because both "NodePort" and "LoadBalancer" types of services have "NodePort" type URLs
                    addNodePortEndpoint(serviceName, servicePort.getNodePort(), protocol, namespace, labels, endpointList);
                }
                if (LOAD_BALANCER.equals(serviceType)) {
                    // Since only "LoadBalancer" type services have "LoadBalancer" type URLs
                    addLoadBalancerEndpoint(serviceName, service, port, protocol, namespace, labels, endpointList);
                }
                // A Special case (can be any of the service types above)
                addExternalIPEndpoint(serviceName, serviceSpec.getExternalIPs(), port, protocol, namespace, labels, endpointList);
            } else if (log.isDebugEnabled()) {
                log.debug("Service:{} Namespace:{} Port:{}/{}  Application level protocol not defined.", serviceName, namespace, servicePort.getPort(), protocol);
            }
        }
    }
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint)

Example 9 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImpl method applicationsApplicationIdKeysKeyTypePut.

/**
 * Update grant types/callback URL
 *
 * @param applicationId Application Id
 * @param keyType       Key Type (Production | Sandbox)
 * @param body          Grant type and callback URL information
 * @param request       msf4j request object
 * @return Updated Key Information
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response applicationsApplicationIdKeysKeyTypePut(String applicationId, String keyType, ApplicationKeysDTO body, Request request) throws NotFoundException {
    try {
        String username = RestApiUtil.getLoggedInUsername(request);
        APIStore apiConsumer = RestApiUtil.getConsumer(username);
        OAuthApplicationInfo oAuthApp = apiConsumer.updateGrantTypesAndCallbackURL(applicationId, keyType, body.getSupportedGrantTypes(), body.getCallbackUrl());
        ApplicationKeysDTO appKeys = ApplicationKeyMappingUtil.fromApplicationKeysToDTO(oAuthApp);
        return Response.ok().entity(appKeys).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while updating '" + keyType + "'-type grant types/callback url of " + "application: " + applicationId;
        Map<String, String> paramList = new HashMap<>();
        paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
        paramList.put(APIMgtConstants.ExceptionsConstants.KEY_TYPE, keyType);
        paramList.put(APIMgtConstants.ExceptionsConstants.CALLBACK_URL, body.getCallbackUrl());
        String grantTypes = null;
        if (body.getSupportedGrantTypes() != null) {
            grantTypes = String.join(",", body.getSupportedGrantTypes());
        }
        paramList.put(APIMgtConstants.ExceptionsConstants.GRANT_TYPES, grantTypes);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : ApplicationKeysDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) HashMap(java.util.HashMap) Map(java.util.Map) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

Example 10 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class APIStoreImpl method updateGrantTypesAndCallbackURL.

@Override
public OAuthApplicationInfo updateGrantTypesAndCallbackURL(String applicationId, String keyType, List<String> grantTypes, String callbackURL) throws APIManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Updating " + keyType + " grant type/callback of App: " + applicationId);
    }
    if (StringUtils.isEmpty(applicationId) || StringUtils.isEmpty(keyType)) {
        String msg = "One of input values is null or empty. Application Id: " + applicationId + " Key Type: " + keyType;
        log.error(msg);
        throw new APIManagementException(msg, ExceptionCodes.OAUTH2_APP_RETRIEVAL_FAILED);
    }
    if (grantTypes == null || grantTypes.isEmpty() || StringUtils.isEmpty(callbackURL)) {
        String msg = "Both Grant Types list and Callback URL can't be null or empty at once.";
        log.error(msg);
        throw new APIManagementException(msg, ExceptionCodes.OAUTH2_APP_RETRIEVAL_FAILED);
    }
    try {
        OAuthApplicationInfo appFromDB = getApplicationDAO().getApplicationKeys(applicationId, keyType);
        OAuthApplicationInfo oAuthApp = getKeyManager().retrieveApplication(appFromDB.getClientId());
        oAuthApp.setGrantTypes(grantTypes);
        oAuthApp.setCallBackURL(callbackURL);
        oAuthApp = getKeyManager().updateApplication(oAuthApp);
        if (log.isDebugEnabled()) {
            log.debug("Updated " + keyType + " grant type/callback of App: " + applicationId);
        }
        return oAuthApp;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while updating " + keyType + " grant type/callback of application: " + applicationId;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3