Search in sources :

Example 1 with CopyFileModel

use of org.ballerinax.docker.generator.models.CopyFileModel 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;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) CopyFileModel(org.ballerinax.docker.generator.models.CopyFileModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 2 with CopyFileModel

use of org.ballerinax.docker.generator.models.CopyFileModel in project kubernetes by ballerinax.

the class KubernetesUtils 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;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) CopyFileModel(org.ballerinax.docker.generator.models.CopyFileModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 CopyFileModel (org.ballerinax.docker.generator.models.CopyFileModel)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)2 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)2