use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processIngressAnnotation.
/**
* Process annotations and create Ingress model object.
*
* @param serviceName Ballerina service name
* @param attachmentNode annotation attachment node.
* @return Ingress model object
*/
IngressModel processIngressAnnotation(String serviceName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
IngressModel ingressModel = new IngressModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
IngressConfiguration ingressConfiguration = IngressConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(ingressConfiguration) {
case name:
ingressModel.setName(getValidName(annotationValue));
break;
case labels:
ingressModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case path:
ingressModel.setPath(annotationValue);
break;
case targetPath:
ingressModel.setTargetPath(annotationValue);
break;
case hostname:
ingressModel.setHostname(annotationValue);
break;
case ingressClass:
ingressModel.setIngressClass(annotationValue);
break;
case enableTLS:
ingressModel.setEnableTLS(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
if (ingressModel.getName() == null || ingressModel.getName().length() == 0) {
ingressModel.setName(getValidName(serviceName) + INGRESS_POSTFIX);
}
if (ingressModel.getHostname() == null || ingressModel.getHostname().length() == 0) {
ingressModel.setHostname(getValidName(serviceName) + INGRESS_HOSTNAME_POSTFIX);
}
return ingressModel;
}
use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processSecrets.
/**
* Process Secrets annotations.
*
* @param attachmentNode Attachment Node
* @return List of @{@link SecretModel} objects
*/
Set<SecretModel> processSecrets(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<SecretModel> secrets = 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) {
SecretModel secretModel = new SecretModel();
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:
secretModel.setName(getValidName(annotationValue));
break;
case mountPath:
secretModel.setMountPath(annotationValue);
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
secretModel.setData(getDataForSecret(data));
break;
case readOnly:
secretModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
secrets.add(secretModel);
}
}
return secrets;
}
use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processServiceAnnotation.
/**
* Process annotations and create service model object.
*
* @param endpointName ballerina service name
* @param attachmentNode annotation attachment node.
* @return Service model object
*/
ServiceModel processServiceAnnotation(String endpointName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
ServiceModel serviceModel = new ServiceModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
ServiceConfiguration serviceConfiguration = ServiceConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(serviceConfiguration) {
case name:
serviceModel.setName(getValidName(annotationValue));
break;
case labels:
serviceModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case serviceType:
serviceModel.setServiceType(annotationValue);
break;
case port:
serviceModel.setPort(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
if (serviceModel.getName() == null) {
serviceModel.setName(getValidName(endpointName) + SVC_POSTFIX);
}
return serviceModel;
}
use of org.wso2.charon3.core.utils.codeutils.Node in project ballerina by ballerina-lang.
the class SymbolEnter method defineNode.
public void defineNode(BLangNode node, SymbolEnv env) {
SymbolEnv prevEnv = this.env;
this.env = env;
node.accept(this);
this.env = prevEnv;
}
use of org.wso2.charon3.core.utils.codeutils.Node in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangVariable varNode) {
// this is a field variable defined for object init function
if (varNode.isField) {
Name varName = names.fromIdNode(varNode.name);
BVarSymbol fieldVar = (BVarSymbol) symResolver.resolveObjectField(varNode.pos, env, varName, env.enclObject.symbol.type.tsymbol);
varNode.type = fieldVar.type;
varName = getFieldSymbolName(((BLangFunction) env.enclInvokable).receiver, varNode);
BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
env.enclObject.initFunction.initFunctionStmts.put(fieldVar, (BLangStatement) createAssignmentStmt(varNode, varSymbol, fieldVar));
varSymbol.docTag = varNode.docTag;
varNode.symbol = varSymbol;
return;
}
// assign the type to var type node
if (varNode.type == null) {
varNode.type = symResolver.resolveTypeNode(varNode.typeNode, env);
}
Name varName = names.fromIdNode(varNode.name);
if (varName == Names.EMPTY || varName == Names.IGNORE) {
// e.g. function foo() (int);
return;
}
BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
varSymbol.docTag = varNode.docTag;
varNode.symbol = varSymbol;
}
Aggregations