src/main/java/org/edgegallery/appstore/application/external/mecm/MecmService.java
public String upLoadPackageToNorth(String token, Release release, String hostList, String tenantId, String params) {
        if (StringUtils.isEmpty(token) || release == null || StringUtils.isEmpty(tenantId)) {
            LOGGER.error("Failed to validate input parameters of north task creation.");
            return null;
        }
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("file", new FileSystemResource(release.getPackageFile().getStorageAddress()));
        body.add("hostList", hostList);
        body.add("appPkgName", release.getAppBasicInfo().getAppName());
        body.add("appPkgVersion", release.getAppBasicInfo().getVersion());
        body.add("appClass", release.getDeployMode());
        body.add("parameters", params);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        headers.set(Consts.ACCESS_TOKEN_STR, token);
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
        String url = northUrl.concat(String.format(MECM_UPLOAD_PACKAGE, tenantId));
        LOGGER.info("the url is:{}", url);
        try {
            ResponseEntity<String> response = REST_TEMPLATE.exchange(url, HttpMethod.POST, requestEntity, String.class);
            if (!HttpStatus.OK.equals(response.getStatusCode())) {
                LOGGER.error("Failed to get http response from MECM, status is {}", response.getStatusCode());
                return null;
            }
            JsonObject jsonBody = new JsonParser().parse(Objects.requireNonNull(response.getBody())).getAsJsonObject();
            String message = jsonBody.get("message").getAsString();
            if (message.equalsIgnoreCase("Failed to create server")) {
                LOGGER.error("Failed to create server.");
                return null;
            }
            return jsonBody.get("mecmPackageId").getAsString();
        } catch (RestClientException | NullPointerException e) {
            LOGGER.error("Failed to upload package to north, exception {}", e.getMessage());
        }
        return null;
    }
/**
     * upload package to mecm-apm.
     *
     * @param token access token
     * @param release app package info
     * @param hostList mec host
     * @param tenantId user id
     * @return Mecm package id
     */
upload package to mecm-apm.
upload package to mecm - apm .
public String upLoadPackageToNorth(String token, Release release, String hostList, String tenantId, String params) {
        if (StringUtils.isEmpty(token) || release == null || StringUtils.isEmpty(tenantId)) {
            LOGGER.error("Failed to validate input parameters of north task creation.");
            return null;
        }
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("file", new FileSystemResource(release.getPackageFile().getStorageAddress()));
        body.add("hostList", hostList);
        body.add("appPkgName", release.getAppBasicInfo().getAppName());
        body.add("appPkgVersion", release.getAppBasicInfo().getVersion());
        body.add("appClass", release.getDeployMode());
        body.add("parameters", params);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        headers.set(Consts.ACCESS_TOKEN_STR, token);
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
        String url = northUrl.concat(String.format(MECM_UPLOAD_PACKAGE, tenantId));
        LOGGER.info("the url is:{}", url);
        try {
            ResponseEntity<String> response = REST_TEMPLATE.exchange(url, HttpMethod.POST, requestEntity, String.class);
            if (!HttpStatus.OK.equals(response.getStatusCode())) {
                LOGGER.error("Failed to get http response from MECM, status is {}", response.getStatusCode());
                return null;
            }
            JsonObject jsonBody = new JsonParser().parse(Objects.requireNonNull(response.getBody())).getAsJsonObject();
            String message = jsonBody.get("message").getAsString();
            if (message.equalsIgnoreCase("Failed to create server")) {
                LOGGER.error("Failed to create server.");
                return null;
            }
            return jsonBody.get("mecmPackageId").getAsString();
        } catch (RestClientException | NullPointerException e) {
            LOGGER.error("Failed to upload package to north, exception {}", e.getMessage());
        }
        return null;
    }
public String upLoadPackageToNorth ( String token , Release release , String hostList , String tenantId , String params ) { if ( StringUtils . isEmpty ( token ) || release == null || StringUtils . isEmpty ( tenantId ) ) { LOGGER . error ( "Failed to validate input parameters of north task creation." ) ; return null ; } MultiValueMap < String , Object > body = new LinkedMultiValueMap < > ( ) ; body . add ( "file" , new FileSystemResource ( release . getPackageFile ( ) . getStorageAddress ( ) ) ) ; body . add ( "hostList" , hostList ) ; body . add ( "appPkgName" , release . getAppBasicInfo ( ) . getAppName ( ) ) ; body . add ( "appPkgVersion" , release . getAppBasicInfo ( ) . getVersion ( ) ) ; body . add ( "appClass" , release . getDeployMode ( ) ) ; body . add ( "parameters" , params ) ; HttpHeaders headers = new HttpHeaders ( ) ; headers . setContentType ( MediaType . MULTIPART_FORM_DATA ) ; headers . set ( Consts . ACCESS_TOKEN_STR , token ) ; HttpEntity < MultiValueMap < String , Object > > requestEntity = new HttpEntity < > ( body , headers ) ; String url = northUrl . concat ( String . format ( MECM_UPLOAD_PACKAGE , tenantId ) ) ; LOGGER . info ( "the url is:{}" , url ) ; try { ResponseEntity < String > response = REST_TEMPLATE . exchange ( url , HttpMethod . POST , requestEntity , String . class ) ; if ( ! HttpStatus . OK . equals ( response . getStatusCode ( ) ) ) { LOGGER . error ( "Failed to get http response from MECM, status is {}" , response . getStatusCode ( ) ) ; return null ; } JsonObject jsonBody = new JsonParser ( ) . parse ( Objects . requireNonNull ( response . getBody ( ) ) ) . getAsJsonObject ( ) ; String message = jsonBody . get ( "message" ) . getAsString ( ) ; if ( message . equalsIgnoreCase ( "Failed to create server" ) ) { LOGGER . error ( "Failed to create server." ) ; return null ; } return jsonBody . get ( "mecmPackageId" ) . getAsString ( ) ; } catch ( RestClientException | NullPointerException e ) { LOGGER . error ( "Failed to upload package to north, exception {}" , e . getMessage ( ) ) ; } return null ; }
upload package to mecm-apm.
upload package to mecm - apm .