Search in sources :

Example 1 with Node

use of org.wso2.carbon.identity.core.model.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processPersistentVolumeClaim.

/**
 * Process PersistentVolumeClaim annotations.
 *
 * @param attachmentNode Attachment Node
 * @return Set of @{@link ConfigMapModel} objects
 */
Set<PersistentVolumeClaimModel> processPersistentVolumeClaim(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<PersistentVolumeClaimModel> volumeClaimModels = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : secretAnnotation) {
            PersistentVolumeClaimModel claimModel = new PersistentVolumeClaimModel();
            List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
                VolumeClaimConfig volumeMountConfig = VolumeClaimConfig.valueOf(annotation.getKey().toString());
                String annotationValue = resolveValue(annotation.getValue().toString());
                switch(volumeMountConfig) {
                    case name:
                        claimModel.setName(getValidName(annotationValue));
                        break;
                    case mountPath:
                        claimModel.setMountPath(annotationValue);
                        break;
                    case accessMode:
                        claimModel.setAccessMode(annotationValue);
                        break;
                    case volumeClaimSize:
                        claimModel.setVolumeClaimSize(annotationValue);
                        break;
                    case readOnly:
                        claimModel.setReadOnly(Boolean.parseBoolean(annotationValue));
                        break;
                    default:
                        break;
                }
            }
            volumeClaimModels.add(claimModel);
        }
    }
    return volumeClaimModels;
}
Also used : PersistentVolumeClaimModel(org.ballerinax.kubernetes.models.PersistentVolumeClaimModel) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 2 with Node

use of org.wso2.carbon.identity.core.model.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processConfigMap.

/**
 * Process ConfigMap annotations.
 *
 * @param attachmentNode Attachment Node
 * @return Set of @{@link ConfigMapModel} objects
 */
Set<ConfigMapModel> processConfigMap(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<ConfigMapModel> configMapModels = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        List<BLangExpression> configAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : configAnnotation) {
            ConfigMapModel configMapModel = new ConfigMapModel();
            List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
                VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
                String annotationValue = resolveValue(annotation.getValue().toString());
                switch(volumeMountConfig) {
                    case name:
                        configMapModel.setName(getValidName(annotationValue));
                        break;
                    case mountPath:
                        configMapModel.setMountPath(annotationValue);
                        break;
                    case isBallerinaConf:
                        configMapModel.setBallerinaConf(Boolean.parseBoolean(annotationValue));
                        break;
                    case data:
                        List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
                        configMapModel.setData(getDataForConfigMap(data));
                        break;
                    case readOnly:
                        configMapModel.setReadOnly(Boolean.parseBoolean(annotationValue));
                        break;
                    default:
                        break;
                }
            }
            configMapModels.add(configMapModel);
        }
    }
    return configMapModels;
}
Also used : ConfigMapModel(org.ballerinax.kubernetes.models.ConfigMapModel) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 3 with Node

use of org.wso2.carbon.identity.core.model.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processPodAutoscalerAnnotation.

/**
 * Process annotations and create service model object.
 *
 * @param attachmentNode annotation attachment node.
 * @return Service model object
 */
PodAutoscalerModel processPodAutoscalerAnnotation(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    PodAutoscalerModel podAutoscalerModel = new PodAutoscalerModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        PodAutoscalerConfiguration podAutoscalerConfiguration = PodAutoscalerConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(podAutoscalerConfiguration) {
            case name:
                podAutoscalerModel.setName(getValidName(annotationValue));
                break;
            case labels:
                podAutoscalerModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case cpuPercentage:
                podAutoscalerModel.setCpuPercentage(Integer.parseInt(annotationValue));
                break;
            case minReplicas:
                podAutoscalerModel.setMinReplicas(Integer.parseInt(annotationValue));
                break;
            case maxReplicas:
                podAutoscalerModel.setMaxReplicas(Integer.parseInt(annotationValue));
                break;
            default:
                break;
        }
    }
    return podAutoscalerModel;
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) PodAutoscalerModel(org.ballerinax.kubernetes.models.PodAutoscalerModel)

Example 4 with Node

use of org.wso2.carbon.identity.core.model.Node in project carbon-apimgt by wso2.

the class StatUpdateClusterMessage method execute.

@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    // update the service variable, a boolean variable representing the stat data publishing in the node
    APIManagerAnalyticsConfiguration instanceOfAPIAnalytics = APIManagerAnalyticsConfiguration.getInstance();
    instanceOfAPIAnalytics.setAnalyticsEnabled(statUpdateStatus);
    // Only change Data publishing information only if they are set
    if (receiverUrl != null && !receiverUrl.isEmpty() && user != null && !user.isEmpty() && password != null && !password.isEmpty()) {
        instanceOfAPIAnalytics.setDasReceiverUrlGroups(receiverUrl);
        instanceOfAPIAnalytics.setDasReceiverServerUser(user);
        instanceOfAPIAnalytics.setDasReceiverServerPassword(password);
    }
    if (log.isDebugEnabled()) {
        log.debug("Updated Stat publishing status to : " + statUpdateStatus);
    }
}
Also used : APIManagerAnalyticsConfiguration(org.wso2.carbon.apimgt.impl.APIManagerAnalyticsConfiguration)

Example 5 with Node

use of org.wso2.carbon.identity.core.model.Node in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method initModels.

/**
 * Initiallize SOAP to REST Operations
 *
 * @return true if extracting operations was successful
 */
private boolean initModels() throws APIMgtWSDLException {
    wsdlDefinition = getWSDLDefinition();
    boolean canProcess = true;
    targetNamespace = wsdlDefinition.getTargetNamespace();
    Types types = wsdlDefinition.getTypes();
    if (types != null) {
        typeList = types.getExtensibilityElements();
    }
    if (typeList != null) {
        for (Object ext : typeList) {
            if (ext instanceof Schema) {
                Schema schema = (Schema) ext;
                Map importedSchemas = schema.getImports();
                Element schemaElement = schema.getElement();
                NodeList schemaNodes = schemaElement.getChildNodes();
                schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
                // gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
                if (importedSchemas != null) {
                    for (Object importedSchemaObj : importedSchemas.keySet()) {
                        String schemaUrl = (String) importedSchemaObj;
                        if (importedSchemas.get(schemaUrl) != null) {
                            Vector vector = (Vector) importedSchemas.get(schemaUrl);
                            for (Object schemaVector : vector) {
                                if (schemaVector instanceof SchemaImport) {
                                    Schema referencedSchema = ((SchemaImport) schemaVector).getReferencedSchema();
                                    if (referencedSchema != null && referencedSchema.getElement() != null) {
                                        if (referencedSchema.getElement().hasChildNodes()) {
                                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(referencedSchema.getElement().getChildNodes()));
                                        } else {
                                            log.warn("The referenced schema : " + schemaUrl + " doesn't have any defined types");
                                        }
                                    } else {
                                        boolean isInlineSchema = false;
                                        for (Object aSchema : typeList) {
                                            if (schemaUrl.equalsIgnoreCase(((Schema) aSchema).getElement().getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
                                                isInlineSchema = true;
                                                break;
                                            }
                                        }
                                        if (isInlineSchema) {
                                            log.debug(schemaUrl + " is already defined inline. Hence continue.");
                                        } else {
                                            log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    log.info("No any imported schemas found in the given wsdl.");
                }
                List schemaIncludes = schema.getIncludes();
                for (Iterator iter = schemaIncludes.iterator(); iter.hasNext(); ) {
                    SchemaReference schemaInclude = (SchemaReference) iter.next();
                    Schema schemaImp = schemaInclude.getReferencedSchema();
                    String schemaLoc = schemaInclude.getSchemaLocationURI();
                    if (schemaImp != null && schemaImp.getElement() != null) {
                        if (schemaImp.getElement().hasChildNodes()) {
                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaImp.getElement().getChildNodes()));
                        } else {
                            log.warn("The referenced schema : " + schemaLoc + " doesn't have any defined types");
                        }
                    }
                }
                if (log.isDebugEnabled()) {
                    Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy()).create();
                    log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
                }
                if (schemaNodeList == null) {
                    log.warn("No schemas found in the type element for target namespace:" + schema.getDocumentBaseURI());
                }
            }
        }
        if (schemaNodeList != null) {
            for (Node node : schemaNodeList) {
                WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
                ModelImpl model = new ModelImpl();
                Property currentProperty = null;
                try {
                    traverseTypeElement(node, null, model, currentProperty);
                } catch (APIManagementException e) {
                    throw new APIMgtWSDLException(e);
                }
                if (StringUtils.isNotBlank(model.getName())) {
                    parameterModelMap.put(model.getName(), model);
                }
                if (wsdlParamDefinition.getDefinitionName() != null) {
                    wsdlParamDefinitions.add(wsdlParamDefinition);
                }
            }
        } else {
            log.info("No schema is defined in the wsdl document");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
    }
    return canProcess;
}
Also used : Types(javax.wsdl.Types) SwaggerFieldsExcludeStrategy(org.wso2.carbon.apimgt.impl.wsdl.util.SwaggerFieldsExcludeStrategy) WSDLParamDefinition(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLParamDefinition) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) GsonBuilder(com.google.gson.GsonBuilder) Schema(javax.wsdl.extensions.schema.Schema) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Gson(com.google.gson.Gson) SchemaReference(javax.wsdl.extensions.schema.SchemaReference) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) Vector(java.util.Vector) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty)

Aggregations

ArrayList (java.util.ArrayList)33 Operation (io.swagger.v3.oas.annotations.Operation)26 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)26 Response (javax.ws.rs.core.Response)26 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)25 Test (org.testng.annotations.Test)24 Node (org.wso2.charon3.core.utils.codeutils.Node)22 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)20 IOException (java.io.IOException)19 Node (org.w3c.dom.Node)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 List (java.util.List)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)16 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)16 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)13 Map (java.util.Map)12 NodeList (org.w3c.dom.NodeList)12