use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processIstioVSAnnotation.
/**
* Process @istio:VirtualService annotation.
*
* @param vsFields Fields of the virtual service annotation.
* @throws KubernetesPluginException Unable to process annotations.
*/
private IstioVirtualServiceModel processIstioVSAnnotation(List<BLangRecordLiteral.BLangRecordKeyValueField> vsFields) throws KubernetesPluginException {
IstioVirtualServiceModel vsModel = new IstioVirtualServiceModel();
for (BLangRecordLiteral.BLangRecordKeyValueField vsField : vsFields) {
switch(VSConfig.valueOf(vsField.getKey().toString())) {
case name:
vsModel.setName(getValidName(getStringValue(vsField.getValue())));
break;
case labels:
vsModel.setLabels(getMap(vsField.getValue()));
break;
case annotations:
vsModel.setAnnotations(getMap(vsField.getValue()));
break;
case hosts:
vsModel.setHosts(getList(vsField.getValue()));
break;
case gateways:
vsModel.setGateways(getList(vsField.getValue()));
break;
case http:
BLangListConstructorExpr httpFields = (BLangListConstructorExpr) vsField.getValue();
List<IstioHttpRoute> httpModels = processHttpAnnotation(httpFields);
vsModel.setHttp(httpModels);
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + vsField.getKey().toString());
}
}
return vsModel;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KnativeSecretAnnotationProcesser method processSecret.
private void processSecret(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<SecretModel> secrets = 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) {
SecretModel secretModel = new SecretModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
SecretMountConfig secretMountConfig = SecretMountConfig.valueOf(annotation.getKey().toString());
switch(secretMountConfig) {
case name:
secretModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
secretModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
secretModel.setAnnotations(getMap(keyValue.getValue()));
break;
case mountPath:
secretModel.setMountPath(getStringValue(annotation.getValue()));
break;
case data:
List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
secretModel.setData(getDataForSecret(data));
break;
case readOnly:
secretModel.setReadOnly(getBooleanValue(annotation.getValue()));
break;
default:
break;
}
}
if (isBlank(secretModel.getName())) {
secretModel.setName(getValidName(nodeID.getValue()) + SECRET_POSTFIX);
}
secrets.add(secretModel);
}
}
KnativeContext.getInstance().getDataHolder().addSecrets(secrets);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KnativeUtils method getExternalFileMap.
/**
* Get the set of external files to copy to docker image.
*
* @param keyValue Value of copyFiles field of Job annotation.
* @return A set of external files
* @throws KubernetesPluginException if an error occur while getting the paths
*/
public static Set<CopyFileModel> getExternalFileMap(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
Set<CopyFileModel> externalFiles = new HashSet<>();
List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
CopyFileModel externalFileModel = new CopyFileModel();
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
switch(annotation.getKey().toString()) {
case "sourceFile":
externalFileModel.setSource(getStringValue(annotation.getValue()));
break;
case "target":
externalFileModel.setTarget(getStringValue(annotation.getValue()));
break;
default:
break;
}
}
if (isBlank(externalFileModel.getSource())) {
throw new KubernetesPluginException("@kubernetes:Deployment copyFiles source cannot be empty.");
}
if (isBlank(externalFileModel.getTarget())) {
throw new KubernetesPluginException("@kubernetes:Deployment copyFiles target cannot be empty.");
}
externalFiles.add(externalFileModel);
}
return externalFiles;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KubernetesUtils method getList.
/**
* Generate array of string using a {@link BLangListConstructorExpr}.
*
* @param expr Array literal.
* @return Convert string.
*/
public static List<String> getList(BLangExpression expr) throws KubernetesPluginException {
if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_EXPR) {
throw new KubernetesPluginException("unable to parse value: " + expr.toString());
} else {
BLangListConstructorExpr array = (BLangListConstructorExpr) expr;
List<String> scopeSet = new LinkedList<>();
for (ExpressionNode bLangExpression : array.getExpressions()) {
scopeSet.add(getStringValue((BLangExpression) bLangExpression));
}
return scopeSet;
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class DeploymentAnnotationProcessor 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