use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class VolumeClaimAnnotationProcessor method processVolumeClaims.
/**
* Process PersistentVolumeClaim annotations.
*
* @param attachmentNode Annotation node.
* @throws KubernetesPluginException When error occurs while parsing the annotations.
*/
private void processVolumeClaims(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<PersistentVolumeClaimModel> volumeClaimModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
List<BLangExpression> secretAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : secretAnnotation) {
PersistentVolumeClaimModel claimModel = new PersistentVolumeClaimModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
VolumeClaimConfig volumeMountConfig = VolumeClaimConfig.valueOf(annotation.getKey().toString());
switch(volumeMountConfig) {
case name:
claimModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
claimModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
claimModel.setAnnotations(getMap(keyValue.getValue()));
break;
case mountPath:
claimModel.setMountPath(getStringValue(annotation.getValue()));
break;
case accessMode:
claimModel.setAccessMode(getStringValue(annotation.getValue()));
break;
case volumeClaimSize:
String amount = getStringValue(annotation.getValue()).replaceAll("\\D+", "");
String format = getStringValue(annotation.getValue()).replace(amount, "");
claimModel.setVolumeClaimSizeAmount(amount);
claimModel.setVolumeClaimSizeFormat(format);
break;
case readOnly:
claimModel.setReadOnly(getBooleanValue(annotation.getValue()));
break;
default:
break;
}
}
volumeClaimModels.add(claimModel);
}
}
KubernetesContext.getInstance().getDataHolder().addPersistentVolumeClaims(volumeClaimModels);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processHttpAnnotation.
/**
* Process http annotation array of the virtual service annotation to a model.
*
* @param httpArray The list of http fields.
* @return Converted list of Istio http routes.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<IstioHttpRoute> processHttpAnnotation(BLangListConstructorExpr httpArray) throws KubernetesPluginException {
List<IstioHttpRoute> httpRoutes = new LinkedList<>();
for (ExpressionNode expression : httpArray.getExpressions()) {
BLangRecordLiteral httpFields = (BLangRecordLiteral) expression;
IstioHttpRoute httpRoute = new IstioHttpRoute();
for (BLangRecordLiteral.BLangRecordKeyValueField httpField : convertRecordFields(httpFields.getFields())) {
switch(HttpRouteConfig.valueOf(httpField.getKey().toString())) {
case route:
BLangListConstructorExpr routeFields = (BLangListConstructorExpr) httpField.getValue();
httpRoute.setRoute(processRoutesAnnotation(routeFields));
break;
case timeout:
httpRoute.setTimeout(getLongValue(httpField.getValue()));
break;
case appendHeaders:
httpRoute.setAppendHeaders(getMap(httpField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + httpField.getKey().toString());
}
}
httpRoutes.add(httpRoute);
}
return httpRoutes;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processRoutesAnnotation.
/**
* Process routes of http annotation to a model.
*
* @param routeArray The list of routes.
* @return A list of istio destination weight models.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<IstioDestinationWeight> processRoutesAnnotation(BLangListConstructorExpr routeArray) throws KubernetesPluginException {
List<IstioDestinationWeight> destinationWeights = new LinkedList<>();
for (ExpressionNode expression : routeArray.getExpressions()) {
BLangRecordLiteral routeFields = (BLangRecordLiteral) expression;
IstioDestinationWeight destinationWeight = new IstioDestinationWeight();
for (BLangRecordLiteral.BLangRecordKeyValueField routeField : convertRecordFields(routeFields.getFields())) {
switch(DestinationWeightConfig.valueOf(routeField.getKey().toString())) {
case destination:
BLangRecordLiteral destinationFields = (BLangRecordLiteral) routeField.getValue();
IstioDestination destination = processDestinationAnnotation(destinationFields);
destinationWeight.setDestination(destination);
break;
case weight:
destinationWeight.setWeight(getIntValue(routeField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + routeField.getKey().toString());
}
}
destinationWeights.add(destinationWeight);
}
return destinationWeights;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KnativeServiceAnnotationProcessor method parsePodTolerationConfiguration.
/**
* Parse pod toleration configurations from a record array.
*
* @param podTolerationValues Pod toleration configuration records.
* @return Pod toleration models.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<PodTolerationModel> parsePodTolerationConfiguration(BLangExpression podTolerationValues) throws KubernetesPluginException {
List<PodTolerationModel> podTolerationModels = new LinkedList<>();
List<BLangExpression> podTolerations = ((BLangListConstructorExpr) podTolerationValues).exprs;
for (BLangExpression podTolerationFieldsAsExpression : podTolerations) {
List<BLangRecordLiteral.BLangRecordKeyValueField> podTolerationFields = convertRecordFields(((BLangRecordLiteral) podTolerationFieldsAsExpression).getFields());
PodTolerationModel podTolerationModel = new PodTolerationModel();
for (BLangRecordLiteral.BLangRecordKeyValueField podTolerationField : podTolerationFields) {
PodTolerationConfiguration podTolerationFieldName = PodTolerationConfiguration.valueOf(podTolerationField.getKey().toString());
switch(podTolerationFieldName) {
case key:
podTolerationModel.setKey(getStringValue(podTolerationField.getValue()));
break;
case operator:
podTolerationModel.setOperator(getStringValue(podTolerationField.getValue()));
break;
case value:
podTolerationModel.setValue(getStringValue(podTolerationField.getValue()));
break;
case effect:
podTolerationModel.setEffect(getStringValue(podTolerationField.getValue()));
break;
case tolerationSeconds:
podTolerationModel.setTolerationSeconds(getIntValue(podTolerationField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown pod toleration field found: " + podTolerationField.getKey().toString());
}
}
podTolerationModels.add(podTolerationModel);
}
return podTolerationModels;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KnativeServiceAnnotationProcessor method getDependsOn.
private Set<String> getDependsOn(BLangRecordLiteral.BLangRecordKeyValueField keyValue) {
Set<String> dependsOnList = new HashSet<>();
List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
dependsOnList.add(bLangExpression.toString());
}
return dependsOnList;
}
Aggregations