src/main/java/org/edgegallery/appstore/application/inner/AppService.java
public void updateAppPackageWithRepoInfo(String parentDir) {

        File swImageDesc = appUtil.getFileFromPackage(parentDir, "Image/SwImageDesc.json");
        updateRepoInfoInSwImageDesc(swImageDesc);
        String unZipPath = dir + File.separator + UUID.randomUUID().toString().replace("-", "");

        File chartsTar = appUtil.getFileFromPackage(parentDir, "/Artifacts/Deployment/Charts/");
        if (chartsTar == null) {
            throw new AppException("failed to find values yaml", ResponseConst.RET_FILE_NOT_FOUND,
                "/Artifacts/Deployment/Charts/");
        }

        try {
            File unZipPathDir = new File(unZipPath);
            if (!unZipPathDir.mkdirs()) {
                LOGGER.info("unZip path has already existed.");
            }

            String chartsTarStr = chartsTar.getCanonicalFile().toString();
            deCompress(chartsTarStr, new File(unZipPath));

            FileUtils.forceDelete(chartsTar);
            File valuesYaml = appUtil.getFileFromPackage(unZipPath, "/values.yaml");
            if (valuesYaml == null) {
                throw new AppException("failed to find values yaml", ResponseConst.RET_FILE_NOT_FOUND, "/values.yaml");
            }

            //update values.yaml
            Map<String, Object> values = loadvaluesYaml(valuesYaml);
            ImgLoc imageLoc = null;
            for (String key : values.keySet()) {
                if (IMAGE_LOCATION.equals(key)) {
                    ModelMapper mapper = new ModelMapper();
                    imageLoc = mapper.map(values.get(IMAGE_LOCATION), ImgLoc.class);
                    LOGGER.info("imageLoc domain {}, project {}", imageLoc.getDomainname(), imageLoc.getProject());
                    break;
                }
            }
            if (imageLoc == null || StringUtils.isEmpty(imageLoc.getDomainname()) || StringUtils.isEmpty(
                imageLoc.getProject())) {
                LOGGER.error("missing image location parameters ");
                throw new AppException("failed to update values yaml, missing image location parameters",
                    ResponseConst.RET_MISS_IMAGE_LOCATION);
            }
            FileUtils.writeStringToFile(valuesYaml, FileUtils.readFileToString(valuesYaml, StandardCharsets.UTF_8)
                    .replace(imageLoc.getDomainname(), appstoreRepoEndpoint).replace(imageLoc.getProject(), "appstore"),
                StandardCharsets.UTF_8, false);

            compress(valuesYaml.getParent(), chartsTarStr);
            LOGGER.info("Charts Parent path is {}", valuesYaml.getParent());
            FileUtils.deleteDirectory(unZipPathDir);
        } catch (IOException e) {
            LOGGER.info("Delete temporary unzip directory failed {}", e.getMessage());
        }
    }
/**
     * Update application package with appstore repo info.
     *
     * @param parentDir parent Dir
     */
Update application package with appstore repo info.
@param parentDir parent Dir
Update application package with appstore repo info . @param parentDir parent Dir
public void updateAppPackageWithRepoInfo(String parentDir) {
        File swImageDesc = appUtil.getFileFromPackage(parentDir, "Image/SwImageDesc.json");
        updateRepoInfoInSwImageDesc(swImageDesc);
        String unZipPath = dir + File.separator + UUID.randomUUID().toString().replace("-", "");
        File chartsTar = appUtil.getFileFromPackage(parentDir, "/Artifacts/Deployment/Charts/");
        if (chartsTar == null) {
            throw new AppException("failed to find values yaml", ResponseConst.RET_FILE_NOT_FOUND,
                "/Artifacts/Deployment/Charts/");
        }
        try {
            File unZipPathDir = new File(unZipPath);
            if (!unZipPathDir.mkdirs()) {
                LOGGER.info("unZip path has already existed.");
            }
            String chartsTarStr = chartsTar.getCanonicalFile().toString();
            deCompress(chartsTarStr, new File(unZipPath));
            FileUtils.forceDelete(chartsTar);
            File valuesYaml = appUtil.getFileFromPackage(unZipPath, "/values.yaml");
            if (valuesYaml == null) {
                throw new AppException("failed to find values yaml", ResponseConst.RET_FILE_NOT_FOUND, "/values.yaml");
            }
            Map<String, Object> values = loadvaluesYaml(valuesYaml);
            ImgLoc imageLoc = null;
            for (String key : values.keySet()) {
                if (IMAGE_LOCATION.equals(key)) {
                    ModelMapper mapper = new ModelMapper();
                    imageLoc = mapper.map(values.get(IMAGE_LOCATION), ImgLoc.class);
                    LOGGER.info("imageLoc domain {}, project {}", imageLoc.getDomainname(), imageLoc.getProject());
                    break;
                }
            }
            if (imageLoc == null || StringUtils.isEmpty(imageLoc.getDomainname()) || StringUtils.isEmpty(
                imageLoc.getProject())) {
                LOGGER.error("missing image location parameters ");
                throw new AppException("failed to update values yaml, missing image location parameters",
                    ResponseConst.RET_MISS_IMAGE_LOCATION);
            }
            FileUtils.writeStringToFile(valuesYaml, FileUtils.readFileToString(valuesYaml, StandardCharsets.UTF_8)
                    .replace(imageLoc.getDomainname(), appstoreRepoEndpoint).replace(imageLoc.getProject(), "appstore"),
                StandardCharsets.UTF_8, false);
            compress(valuesYaml.getParent(), chartsTarStr);
            LOGGER.info("Charts Parent path is {}", valuesYaml.getParent());
            FileUtils.deleteDirectory(unZipPathDir);
        } catch (IOException e) {
            LOGGER.info("Delete temporary unzip directory failed {}", e.getMessage());
        }
    }
public void updateAppPackageWithRepoInfo ( String parentDir ) { File swImageDesc = appUtil . getFileFromPackage ( parentDir , "Image/SwImageDesc.json" ) ; updateRepoInfoInSwImageDesc ( swImageDesc ) ; String unZipPath = dir + File . separator + UUID . randomUUID ( ) . toString ( ) . replace ( "-" , "" ) ; File chartsTar = appUtil . getFileFromPackage ( parentDir , "/Artifacts/Deployment/Charts/" ) ; if ( chartsTar == null ) { throw new AppException ( "failed to find values yaml" , ResponseConst . RET_FILE_NOT_FOUND , "/Artifacts/Deployment/Charts/" ) ; } try { File unZipPathDir = new File ( unZipPath ) ; if ( ! unZipPathDir . mkdirs ( ) ) { LOGGER . info ( "unZip path has already existed." ) ; } String chartsTarStr = chartsTar . getCanonicalFile ( ) . toString ( ) ; deCompress ( chartsTarStr , new File ( unZipPath ) ) ; FileUtils . forceDelete ( chartsTar ) ; File valuesYaml = appUtil . getFileFromPackage ( unZipPath , "/values.yaml" ) ; if ( valuesYaml == null ) { throw new AppException ( "failed to find values yaml" , ResponseConst . RET_FILE_NOT_FOUND , "/values.yaml" ) ; } Map < String , Object > values = loadvaluesYaml ( valuesYaml ) ; ImgLoc imageLoc = null ; for ( String key : values . keySet ( ) ) { if ( IMAGE_LOCATION . equals ( key ) ) { ModelMapper mapper = new ModelMapper ( ) ; imageLoc = mapper . map ( values . get ( IMAGE_LOCATION ) , ImgLoc . class ) ; LOGGER . info ( "imageLoc domain {}, project {}" , imageLoc . getDomainname ( ) , imageLoc . getProject ( ) ) ; break ; } } if ( imageLoc == null || StringUtils . isEmpty ( imageLoc . getDomainname ( ) ) || StringUtils . isEmpty ( imageLoc . getProject ( ) ) ) { LOGGER . error ( "missing image location parameters " ) ; throw new AppException ( "failed to update values yaml, missing image location parameters" , ResponseConst . RET_MISS_IMAGE_LOCATION ) ; } FileUtils . writeStringToFile ( valuesYaml , FileUtils . readFileToString ( valuesYaml , StandardCharsets . UTF_8 ) . replace ( imageLoc . getDomainname ( ) , appstoreRepoEndpoint ) . replace ( imageLoc . getProject ( ) , "appstore" ) , StandardCharsets . UTF_8 , false ) ; compress ( valuesYaml . getParent ( ) , chartsTarStr ) ; LOGGER . info ( "Charts Parent path is {}" , valuesYaml . getParent ( ) ) ; FileUtils . deleteDirectory ( unZipPathDir ) ; } catch ( IOException e ) { LOGGER . info ( "Delete temporary unzip directory failed {}" , e . getMessage ( ) ) ; } }
Update application package with appstore repo info.
Update application package with appstore repo info .
//update values.yaml