use of org.wso2.carbon.apimgt.keymgt.model.entity.Application 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.carbon.apimgt.keymgt.model.entity.Application in project carbon-apimgt by wso2.
the class ThrottlerUtil method addDefaultAdvancedThrottlePolicies.
/**
* Deploy default throttle polices at startup
*
* @throws APIManagementException throws if any exception occured
*/
public static void addDefaultAdvancedThrottlePolicies() throws APIManagementException {
int[] requestCount = new int[] { 50, 20, 10, Integer.MAX_VALUE };
// Adding application level throttle policies
String[] appPolicies = new String[] { ThrottleConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, ThrottleConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, ThrottleConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, ThrottleConstants.DEFAULT_APP_POLICY_UNLIMITED };
String[] appPolicyDecs = new String[] { ThrottleConstants.DEFAULT_APP_POLICY_LARGE_DESC, ThrottleConstants.DEFAULT_APP_POLICY_MEDIUM_DESC, ThrottleConstants.DEFAULT_APP_POLICY_SMALL_DESC, ThrottleConstants.DEFAULT_APP_POLICY_UNLIMITED_DESC };
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
String policyName;
// Add application level throttle policies
for (int i = 0; i < appPolicies.length; i++) {
policyName = appPolicies[i];
if (!isPolicyExist(APIMgtAdminService.PolicyLevel.application, policyName)) {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(policyName);
applicationPolicy.setUuid(UUID.randomUUID().toString());
applicationPolicy.setDisplayName(policyName);
applicationPolicy.setDescription(appPolicyDecs[i]);
applicationPolicy.setDeployed(true);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
RequestCountLimit requestCountLimit = new RequestCountLimit(ThrottleConstants.TIME_UNIT_MINUTE, 1, requestCount[i]);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setLimit(requestCountLimit);
applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
policyDAO.addApplicationPolicy(applicationPolicy);
}
}
// Adding Subscription level policies
int[] requestCountSubPolicies = new int[] { 5000, 2000, 1000, 500, Integer.MAX_VALUE };
String[] subPolicies = new String[] { ThrottleConstants.DEFAULT_SUB_POLICY_GOLD, ThrottleConstants.DEFAULT_SUB_POLICY_SILVER, ThrottleConstants.DEFAULT_SUB_POLICY_BRONZE, ThrottleConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED, ThrottleConstants.DEFAULT_SUB_POLICY_UNLIMITED };
String[] subPolicyDecs = new String[] { ThrottleConstants.DEFAULT_SUB_POLICY_GOLD_DESC, ThrottleConstants.DEFAULT_SUB_POLICY_SILVER_DESC, ThrottleConstants.DEFAULT_SUB_POLICY_BRONZE_DESC, ThrottleConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED_DESC, ThrottleConstants.DEFAULT_SUB_POLICY_UNLIMITED_DESC };
for (int i = 0; i < subPolicies.length; i++) {
policyName = subPolicies[i];
if (!isPolicyExist(APIMgtAdminService.PolicyLevel.subscription, policyName)) {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(policyName);
subscriptionPolicy.setUuid(UUID.randomUUID().toString());
subscriptionPolicy.setDisplayName(policyName);
subscriptionPolicy.setDescription(subPolicyDecs[i]);
subscriptionPolicy.setDeployed(true);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
RequestCountLimit requestCountLimit = new RequestCountLimit(ThrottleConstants.TIME_UNIT_MINUTE, 1, requestCountSubPolicies[i]);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setLimit(requestCountLimit);
subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
subscriptionPolicy.setStopOnQuotaReach(true);
subscriptionPolicy.setBillingPlan(ThrottleConstants.BILLING_PLAN_FREE);
policyDAO.addSubscriptionPolicy(subscriptionPolicy);
}
}
// Adding Resource level policies
String[] apiPolicies = new String[] { ThrottleConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN, ThrottleConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN, ThrottleConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN, ThrottleConstants.DEFAULT_API_POLICY_UNLIMITED };
String[] apiPolicyDecs = new String[] { ThrottleConstants.DEFAULT_API_POLICY_ULTIMATE_DESC, ThrottleConstants.DEFAULT_API_POLICY_PLUS_DESC, ThrottleConstants.DEFAULT_API_POLICY_BASIC_DESC, ThrottleConstants.DEFAULT_API_POLICY_UNLIMITED_DESC };
int[] requestCountApiPolicies = new int[] { 50000, 20000, 10000, Integer.MAX_VALUE };
for (int i = 0; i < apiPolicies.length; i++) {
policyName = apiPolicies[i];
if (!isPolicyExist(APIMgtAdminService.PolicyLevel.api, policyName)) {
APIPolicy apiPolicy = new APIPolicy(policyName);
apiPolicy.setUuid(UUID.randomUUID().toString());
apiPolicy.setDisplayName(policyName);
apiPolicy.setDescription(apiPolicyDecs[i]);
apiPolicy.setUserLevel(ThrottleConstants.API_POLICY_API_LEVEL);
apiPolicy.setDeployed(true);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
RequestCountLimit requestCountLimit = new RequestCountLimit(ThrottleConstants.TIME_UNIT_MINUTE, 1, requestCountApiPolicies[i]);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setLimit(requestCountLimit);
apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
policyDAO.addApiPolicy(apiPolicy);
}
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Application in project carbon-apimgt by wso2.
the class ApplicationDeletionWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (application == null) {
// this is when complete method is executed through workflow rest api
this.application = applicationDAO.getApplication(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application Deletion workflow complete: Approved");
}
applicationDAO.deleteApplication(getWorkflowReference());
try {
getApiGateway().deleteApplication(application.getId());
} catch (GatewayException ex) {
// This log is not harm to therefore not rethrow
log.warn("Failed to send the Application Deletion Event ", ex);
}
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application Deletion workflow complete: Rejected");
}
}
updateWorkflowEntries(this);
return response;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Application in project carbon-apimgt by wso2.
the class ApplicationUpdateWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
String appId = getWorkflowReference();
String name = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_NAME);
String updatedUser = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_UPDATEDBY);
String applicationId = getWorkflowReference();
String tier = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_TIER);
String policyId = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_POLICY_ID);
String description = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_DESCRIPTION);
String permission = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_PERMISSION);
Application application = new Application(name, updatedUser);
application.setPolicy(new ApplicationPolicy(policyId, tier));
application.setDescription(description);
application.setId(applicationId);
application.setUpdatedUser(updatedUser);
application.setPermissionString(permission);
application.setUpdatedTime(LocalDateTime.now());
if (existingApplication == null && updatedApplication == null) {
// this is when complete method is executed through workflow rest api
existingApplication = applicationDAO.getApplication(appId);
updatedApplication = application;
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application update workflow complete: Approved");
}
application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
applicationDAO.updateApplication(appId, application);
try {
getApiGateway().updateApplication(application);
} catch (GatewayException ex) {
// This log is not harm to therefore not rethrow
log.warn("Failed to send the Application Update Event ", ex);
}
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application update workflow complete: Rejected");
}
String existingAppStatus = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS);
applicationDAO.updateApplicationState(appId, existingAppStatus);
}
updateWorkflowEntries(this);
return response;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Application in project carbon-apimgt by wso2.
the class ApprovalWorkflowExecutor method complete.
/**
* Complete the external process status
* Based on the workflow status we will update the status column of the
* Application table
*
* @param workFlow - Workflow
*/
public WorkflowResponse complete(Workflow workFlow) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing complete() in Workflow for " + workFlow.getWorkflowType());
}
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(workFlow.getStatus());
return workflowResponse;
}
Aggregations