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);
}
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);
}
}
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);
}
}
}
}
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();
}
}
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());
}
}
Aggregations