use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method startMapStructLiteral.
public void startMapStructLiteral() {
BLangRecordLiteral literalNode = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode();
recordLiteralNodes.push(literalNode);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral in project kubernetes by ballerinax.
the class KubernetesPlugin method process.
@Override
public void process(EndpointNode endpointNode, List<AnnotationAttachmentNode> annotations) {
String endpointName = endpointNode.getName().getValue();
ServiceModel serviceModel = null;
setCanProcess(true);
for (AnnotationAttachmentNode attachmentNode : annotations) {
String annotationKey = attachmentNode.getAnnotationName().getValue();
try {
switch(annotationKey) {
case "Service":
serviceModel = kubernetesAnnotationProcessor.processServiceAnnotation(endpointName, attachmentNode);
kubernetesDataHolder.addServiceModel(endpointName, serviceModel);
break;
case "Deployment":
kubernetesDataHolder.setDeploymentModel(kubernetesAnnotationProcessor.processDeployment(attachmentNode));
break;
default:
break;
}
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, endpointNode.getPosition(), e.getMessage());
}
}
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangEndpoint) endpointNode).configurationExpr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
String key = keyValue.getKey().toString();
switch(key) {
case "port":
int port = Integer.parseInt(keyValue.getValue().toString());
kubernetesDataHolder.addPort(port);
if (serviceModel != null) {
serviceModel.setPort(port);
}
break;
case "secureSocket":
List<BLangRecordLiteral.BLangRecordKeyValue> sslKeyValues = ((BLangRecordLiteral) keyValue.valueExpr).getKeyValuePairs();
try {
Set<SecretModel> secretModels = kubernetesAnnotationProcessor.processSecureSocketAnnotation(endpointName, sslKeyValues);
kubernetesDataHolder.addEndpointSecret(endpointName, secretModels);
kubernetesDataHolder.addSecrets(secretModels);
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, null, e.getMessage());
}
break;
default:
break;
}
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processDeployment.
/**
* Process annotations and create deployment model object.
*
* @param attachmentNode annotation attachment node.
* @return Deployment model object
*/
DeploymentModel processDeployment(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
DeploymentModel deploymentModel = new DeploymentModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
DeploymentConfiguration deploymentConfiguration = DeploymentConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(deploymentConfiguration) {
case name:
deploymentModel.setName(getValidName(annotationValue));
break;
case labels:
deploymentModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case enableLiveness:
deploymentModel.setEnableLiveness(annotationValue);
break;
case livenessPort:
deploymentModel.setLivenessPort(Integer.parseInt(annotationValue));
break;
case initialDelaySeconds:
deploymentModel.setInitialDelaySeconds(Integer.parseInt(annotationValue));
break;
case periodSeconds:
deploymentModel.setPeriodSeconds(Integer.parseInt(annotationValue));
break;
case username:
deploymentModel.setUsername(annotationValue);
break;
case env:
deploymentModel.setEnv(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case password:
deploymentModel.setPassword(annotationValue);
break;
case baseImage:
deploymentModel.setBaseImage(annotationValue);
break;
case push:
deploymentModel.setPush(Boolean.valueOf(annotationValue));
break;
case buildImage:
deploymentModel.setBuildImage(Boolean.valueOf(annotationValue));
break;
case image:
deploymentModel.setImage(annotationValue);
break;
case dockerHost:
deploymentModel.setDockerHost(annotationValue);
break;
case dockerCertPath:
deploymentModel.setDockerCertPath(annotationValue);
break;
case imagePullPolicy:
deploymentModel.setImagePullPolicy(annotationValue);
break;
case replicas:
deploymentModel.setReplicas(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
return deploymentModel;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral 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.ballerinalang.compiler.tree.expressions.BLangRecordLiteral 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;
}
Aggregations