当前位置: 首页>>代码示例>>Java>>正文


Java Operation.addRequestHeader方法代码示例

本文整理汇总了Java中com.vmware.xenon.common.Operation.addRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.addRequestHeader方法的具体用法?Java Operation.addRequestHeader怎么用?Java Operation.addRequestHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vmware.xenon.common.Operation的用法示例。


在下文中一共展示了Operation.addRequestHeader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleGet

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handleGet(Operation get) {
    /* TODO: enable tracing outbound requests here.
     * doing so requires that ServiceHost.queueOrScheduleRequestInternal - which does OperationContext switching,
     * capture and activate the SpanContext.
     */
    get.addRequestHeader(
            Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    Operation getState = Operation.createGet(getHost(), "/stateful/foo")
            .setCompletion((operation, error) -> {
                get.setBody(operation.getBody(TestStatefulService.State.class));
                get.complete();
            });
    this.sendRequest(getState);
}
 
开发者ID:vmware,项目名称:xenon-utils,代码行数:17,代码来源:TestStatelessService.java

示例2: getPermissions

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private DeferredResult<PermissionList> getPermissions(
        AuthCredentialsServiceState credentials) {

    logFine(() -> String.format("Retrieving permissions for subscription with id [%s]",
            credentials.userLink));

    String uriStr = AdapterUriUtil.expandUriPathTemplate(PROVIDER_PERMISSIONS_URI,
            credentials.userLink, AUTHORIZATION_NAMESPACE);
    URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr),
            QUERY_PARAM_API_VERSION, PROVIDER_REST_API_VERSION);

    Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);

    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX
                        + getAzureConfig(credentials).getToken(AzureUtils.getAzureBaseUri()));
    } catch (IOException e) {
        return DeferredResult.failed(e);
    }
    return sendWithDeferredResult(operation, PermissionList.class);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:26,代码来源:AzureEndpointAdapterService.java

示例3: testDeleteRequestHeader

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testDeleteRequestHeader() throws Throwable {
    EndpointService.EndpointState startState = buildValidStartState();
    EndpointService.EndpointState returnState = postServiceSynchronously(
            EndpointService.FACTORY_LINK,
            startState, EndpointState.class);

    Operation deleteOperation = Operation
            .createDelete(UriUtils.buildUri(this.host, returnState.documentSelfLink));
    // custom header is not set in delete request, expect failure
    this.host.sendAndWaitExpectFailure(deleteOperation);

    // set custom header
    deleteOperation.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME,
            ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);
    // custom header is set in delete request, expect success
    this.host.sendAndWaitExpectSuccess(deleteOperation);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:19,代码来源:EndpointServiceTest.java

示例4: doInstanceDelete

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Delete endpoint
 *
 */
private void doInstanceDelete(EndpointRemovalTaskState currentState, SubStage next) {
    EndpointState endpoint = currentState.endpoint;

    Operation crdOp = Operation.createDelete(createInventoryUri(this.getHost(),
            endpoint.authCredentialsLink));
    Operation epOp = Operation.createDelete(createInventoryUri(this.getHost(),
            endpoint.documentSelfLink));
    // custom header identifier for endpoint service to validate before deleting endpoint
    epOp.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME,
            ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);

    OperationJoin.create(crdOp, epOp).setCompletion((ops, exc) -> {
        if (exc != null) {
            // failing to delete the endpoint itself is considered a critical error
            Throwable endpointRemovalException = exc.get(epOp.getId());
            if (endpointRemovalException != null) {
                sendFailureSelfPatch(endpointRemovalException);
                return;
            }

            // other removal exceptions are just warnings
            logFine(() -> String.format("Failed delete some of the associated resources,"
                    + " reason %s", Utils.toString(exc)));
        }
        // Endpoint and AuthCredentials are deleted; mark the operation as complete
        sendSelfPatch(TaskStage.STARTED, next);
    }).sendWith(this);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:33,代码来源:EndpointRemovalTaskService.java

示例5: assumeIdentity

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Inject user identity into operation context.
 *
 * @param service the service invoking the operation
 * @param op operation for which the auth context needs to be set
 * @param userServicePath user document link
 * @throws GeneralSecurityException any generic security exception
 */
public static void assumeIdentity(StatefulService service, Operation op,
        String userServicePath)
        throws GeneralSecurityException {
    Claims.Builder builder = new Claims.Builder();
    builder.setSubject(userServicePath);
    Claims claims = builder.getResult();
    String token = service.getTokenSigner().sign(claims);

    // Setting the AuthContext to null, so that xenon uses the token instead.
    service.setAuthorizationContext(op, null);
    op.addRequestHeader(Operation.REQUEST_AUTH_TOKEN_HEADER, token);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TaskUtils.java

示例6: addDefaultRequestHeaders

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Add the default headers applicable to all API calls.
 * @param operation operation to perform.
 * @param accessToken API key for authorization.
 */
static void addDefaultRequestHeaders(Operation operation, String accessToken) {
    operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
            AzureConstants.AUTH_HEADER_BEARER_PREFIX + accessToken);
    operation.addRequestHeader(AzureCostConstants.API_VERSION_HEADER,
            AzureCostConstants.API_VERSION_HEADER_VALUE);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:12,代码来源:AzureCostHelper.java

示例7: getStorageAccounts

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private void getStorageAccounts(AzureStorageStatsDataHolder statsData,
        StorageMetricsStages next) {
    String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_STORAGE_ACCOUNTS,
            statsData.parentAuth.userLink);
    URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr),
            QUERY_PARAM_API_VERSION, STORAGE_ACCOUNT_REST_API_VERSION);

    Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX +
                        statsData.azureClients.credentials.getToken(AZURE_CORE_MANAGEMENT_URI));
    } catch (Exception ex) {
        this.handleError(statsData, ex);
        return;
    }

    operation.setCompletion((op, er) -> {
        if (er != null) {
            handleError(statsData, er);
            return;
        }

        StorageAccountResultList results = op.getBody(StorageAccountResultList.class);
        List<StorageAccount> storageAccounts = results.value;

        // If there are no storage accounts in Azure, the are no bytes being used/billed
        if (storageAccounts == null || storageAccounts.size() == 0) {
            statsData.stage = StorageMetricsStages.FINISHED;
            handleStorageMetricDiscovery(statsData);
            return;
        }

        logFine(() -> String.format("Retrieved %d storage accounts from Azure",
                storageAccounts.size()));

        for (StorageAccount storageAccount : storageAccounts) {
            statsData.storageAccounts.put(storageAccount.id, storageAccount);
        }
        logFine(() -> String.format("Processing %d storage accounts",
                statsData.storageAccounts.size()));

        statsData.stage = next;
        handleStorageMetricDiscovery(statsData);
    });
    sendRequest(operation);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:51,代码来源:AzureComputeHostStorageStatsGatherer.java

示例8: getMetricDefinitions

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Get the metric definitions from Azure using the Endpoint "/metricDefinitions"
 *
 * @param statsData
 * @throws URISyntaxException
 * @throws IOException
 */
private void getMetricDefinitions(AzureStatsDataHolder statsData)
        throws URISyntaxException, IOException {
    String azureInstanceId = statsData.computeDesc.id;
    URI uri = UriUtils.buildUri(new URI(AzureUtils.getAzureBaseUri()), azureInstanceId,
            AzureConstants.METRIC_DEFINITIONS_ENDPOINT);
    // Adding a filter to avoid huge data flow on the network
    /*
     * VSYM-656: https://jira-hzn.eng.vmware.com/browse/VSYM-656
     * Remove the filter when Unit of a metric is required.
     */
    uri = UriUtils.extendUriWithQuery(uri,
            AzureConstants.QUERY_PARAM_API_VERSION,
            AzureConstants.DIAGNOSTIC_SETTING_API_VERSION,
            AzureConstants.QUERY_PARAM_FILTER, AzureConstants.METRIC_DEFINITIONS_MEMORY_FILTER);
    Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
            AzureConstants.AUTH_HEADER_BEARER_PREFIX + statsData.credentials.getToken(AzureUtils.getAzureBaseUri()));
    operation.setCompletion((op, ex) -> {
        if (ex != null) {
            statsData.taskManager.patchTaskToFailure(ex);
            return;
        }
        MetricDefinitions metricDefinitions = op.getBody(MetricDefinitions.class);
        DateTimeFormatter dateTimeFormatter = DateTimeFormat
                .forPattern(AzureConstants.METRIC_TIME_FORMAT);
        if (metricDefinitions.getValues() != null &&
                !metricDefinitions.getValues().isEmpty()) {
            for (MetricAvailability metricAvailability : metricDefinitions.getValues().get(0)
                    .getMetricAvailabilities()) {
                if (metricAvailability.getTimeGrain()
                        .equals(AzureConstants.METRIC_TIME_GRAIN_1_HOUR)) {
                    Location location = metricAvailability.getLocation();
                    Date mostRecentTableDate = null;
                    for (TableInfo tableInfo : location.getTableInfo()) {
                        Date startDate = dateTimeFormatter.parseDateTime(tableInfo.getStartTime())
                                .toDate();
                        if (mostRecentTableDate == null || startDate.after(mostRecentTableDate)) {
                            mostRecentTableDate = startDate;
                            statsData.tableName = tableInfo.getTableName();
                        }
                    }
                    statsData.partitionValue = location.getPartitionKey();
                }
            }
        }
        if (statsData.tableName != null && statsData.tableName.length() > 0) {
            try {
                getMetrics(statsData);
            } catch (Exception e) {
                statsData.taskManager.patchTaskToFailure(e);
            }
        } else {
            patchEmptyResponse(statsData);
        }
    });
    sendRequest(operation);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:66,代码来源:AzureComputeStatsGatherer.java

示例9: getStorageAccounts

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Retrieve storage accounts from Azure.
 */
private void getStorageAccounts(StorageEnumContext context, StorageEnumStages next) {
    String uriStr = context.enumNextPageLink;
    URI uri;

    if (uriStr == null) {
        uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_STORAGE_ACCOUNTS,
                context.endpointAuth.userLink);
        uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr),
                QUERY_PARAM_API_VERSION, STORAGE_ACCOUNT_REST_API_VERSION);
    } else {
        uri = UriUtils.buildUri(uriStr);
    }

    context.storageAccountsToUpdateCreate.clear();
    context.storageAccountBlobUriMap.clear();
    context.storageAccountMap.clear();

    Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX + context.azureSdkClients.credentials
                        .getToken(AzureUtils.getAzureBaseUri()));
    } catch (Exception ex) {
        this.handleError(context, ex);
        return;
    }

    operation.setCompletion((op, er) -> {
        if (er != null) {
            op.complete();
            handleError(context, er);
            return;
        }

        StorageAccountResultList results = op.getBody(StorageAccountResultList.class);
        op.complete();

        List<StorageAccount> storageAccounts = results.value;
        context.apiStorageAccountsCount += results.value.size();

        // If there are no storage accounts in Azure move to storage account cleanup.
        if (storageAccounts == null || storageAccounts.size() == 0) {
            context.subStage = StorageEnumStages.DISASSOCIATE_STORAGE_DESCRIPTIONS;
            handleSubStage(context);
            return;
        }

        context.enumNextPageLink = results.nextLink;

        logFine(() -> String.format("Retrieved %d storage accounts from Azure",
                storageAccounts.size()));

        for (StorageAccount storageAccount : storageAccounts) {
            String id = canonizeId(storageAccount.id);
            storageAccount.id = id;
            context.storageAccountsToUpdateCreate.put(id, storageAccount);
            context.storageAccountIds.add(id);
            context.storageAccountMap.put(id, storageAccount);
        }

        logFine(() -> String.format("Processing %d storage accounts",
                context.storageAccountIds.size()));

        context.subStage = next;
        handleSubStage(context);
    });
    sendRequest(operation);
    context.apiListStorageAccounts++;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:76,代码来源:AzureStorageEnumerationAdapterService.java

示例10: getVirtualNetworks

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
 * Retrieve a page of Virtual Network resources from azure, based on the provided compute host
 * description.
 */
private void getVirtualNetworks(NetworkEnumContext context, NetworkEnumStages next) {
    logFine(() -> "Enumerating Virtual Networks from Azure.");

    URI uri;
    if (context.enumNextPageLink == null) {
        // First request to fetch Virtual Networks from Azure.
        String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_VIRTUAL_NETWORKS_URI,
                context.endpointAuth.userLink);
        uri = UriUtils.extendUriWithQuery(
                UriUtils.buildUri(uriStr),
                QUERY_PARAM_API_VERSION, NETWORK_REST_API_VERSION);
    } else {
        // Request to fetch next page of Virtual Networks from Azure.
        uri = UriUtils.buildUri(context.enumNextPageLink);
    }

    final Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX
                        + context.credentials.getToken(AzureUtils.getAzureBaseUri()));
    } catch (Exception ex) {
        handleError(context, ex);
        return;
    }

    operation.setCompletion((op, ex) -> {
        op.complete();
        if (ex != null) {
            handleError(context, ex);
            return;
        }

        VirtualNetworkListResult results = op.getBody(VirtualNetworkListResult.class);
        List<VirtualNetwork> virtualNetworks = results.value;

        // If there are no Virtual Networks in Azure we directly skip over to deletion phase.
        if (virtualNetworks == null || virtualNetworks.size() == 0) {
            handleSubStage(context, NetworkEnumStages.DELETE_NETWORK_STATES);
            return;
        }

        // Store next page link.
        context.enumNextPageLink = results.nextLink;

        logFine(() -> String.format("Retrieved %d Virtual Networks from Azure",
                virtualNetworks.size()));
        logFine(() -> String.format("Next page link %s", context.enumNextPageLink));

        // Store virtual networks for further processing during the next stages.
        virtualNetworks.forEach(virtualNetwork -> {
            context.addVirtualNetwork(virtualNetwork);
        });

        logFine(() -> String.format("Processing %d virtual networks",
                context.virtualNetworks.size()));

        handleSubStage(context, next);
    });

    sendRequest(operation);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:70,代码来源:AzureNetworkEnumerationAdapterService.java

示例11: getExternalResources

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public DeferredResult<RemoteResourcesPage> getExternalResources(String nextPageLink) {
    URI uri;
    if (nextPageLink == null) {
        // First request to fetch Resource Groups from Azure.
        String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_RESOURCE_GROUPS_URI,
                this.request.endpointAuth.userLink);
        uri = UriUtils.extendUriWithQuery(
                UriUtils.buildUri(uriStr),
                QUERY_PARAM_API_VERSION, RESOURCE_GROUP_REST_API_VERSION);
    } else {
        // Request to fetch next page of Virtual Networks from Azure.
        uri = UriUtils.buildUri(nextPageLink);
    }

    final Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX + this.credentials.getToken(AzureUtils.getAzureBaseUri()));
    } catch (Exception ex) {
        return DeferredResult.failed(ex);
    }

    return this.service.sendWithDeferredResult(operation, ResourceGroupListResult.class)
            .thenApply(results -> {
                RemoteResourcesPage page = new RemoteResourcesPage();

                if (results.value != null) {
                    results.value.forEach(resourceGroup -> {
                        page.resourcesPage.put(AzureUtils.canonizeId
                                (resourceGroup.id), resourceGroup);
                    });
                }
                page.nextPageLink = results.nextLink;

                return page;
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:43,代码来源:AzureResourceGroupEnumerationAdapterService.java

示例12: getExternalResources

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public DeferredResult<RemoteResourcesPage> getExternalResources(String nextPageLink) {

    this.securityGroupRGStates.clear();

    URI uri;
    if (nextPageLink == null) {
        // First request to fetch Network Security Groups from Azure.
        String uriStr = AdapterUriUtil
                .expandUriPathTemplate(LIST_NETWORK_SECURITY_GROUP_URI,
                        this.request.endpointAuth.userLink);
        uri = UriUtils.extendUriWithQuery(
                UriUtils.buildUri(uriStr),
                QUERY_PARAM_API_VERSION, NETWORK_REST_API_VERSION);
    } else {
        // Request to fetch next page of Network Security Groups from Azure.
        uri = UriUtils.buildUri(nextPageLink);
    }

    final Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER,
            Operation.MEDIA_TYPE_APPLICATION_JSON);
    try {
        operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
                AUTH_HEADER_BEARER_PREFIX + this.credentials.getToken(AzureUtils.getAzureBaseUri()));
    } catch (Exception ex) {
        return DeferredResult.failed(ex);
    }

    return this.service
            .sendWithDeferredResult(operation, NetworkSecurityGroupListResult.class)
            .thenApply(results -> {
                RemoteResourcesPage page = new RemoteResourcesPage();

                if (results.value != null) {
                    results.value.forEach(securityGroup -> {
                        page.resourcesPage.put(securityGroup.id, securityGroup);
                    });
                }
                page.nextPageLink = results.nextLink;

                return page;
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:47,代码来源:AzureSecurityGroupEnumerationAdapterService.java


注:本文中的com.vmware.xenon.common.Operation.addRequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。