/// <summary> /// Get the errors of a work request. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> public async Task <ListWorkRequestErrorsResponse> ListWorkRequestErrors(ListWorkRequestErrorsRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called listWorkRequestErrors"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/workRequests/{workRequestId}/errors".Trim('/'))); HttpMethod method = new HttpMethod("Get"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken); } else { responseMessage = await this.restClient.HttpSend(requestMessage); } return(Converter.FromHttpResponseMessage <ListWorkRequestErrorsResponse>(responseMessage)); } catch (Exception e) { logger.Error($"ListWorkRequestErrors failed with error: {e.Message}"); throw; } }
protected override void ProcessRecord() { base.ProcessRecord(); ListWorkRequestErrorsRequest request; try { request = new ListWorkRequestErrorsRequest { WorkRequestId = WorkRequestId, OpcRequestId = OpcRequestId, Page = Page, Limit = Limit, SortBy = SortBy, SortOrder = SortOrder }; IEnumerable <ListWorkRequestErrorsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null) { WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources."); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
protected override void ProcessRecord() { base.ProcessRecord(); ListWorkRequestErrorsRequest request; try { request = new ListWorkRequestErrorsRequest { WorkRequestId = WorkRequestId, OpcRequestId = OpcRequestId, Page = Page, Limit = Limit }; IEnumerable <ListWorkRequestErrorsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Creates a new enumerable which will iterate over the WorkRequestError objects /// contained in responses from the ListWorkRequestErrors operation. This enumerable will fetch more data from the server as needed. /// </summary> /// <param name="request">The request object containing the details to send</param> /// <param name="retryConfiguration">The configuration for retrying, may be null</param> /// <param name="cancellationToken">The cancellation token object</param> /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns> public IEnumerable <WorkRequestError> ListWorkRequestErrorsRecordEnumerator(ListWorkRequestErrorsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { return(new Common.Utils.ResponseRecordEnumerable <ListWorkRequestErrorsRequest, ListWorkRequestErrorsResponse, WorkRequestError>( response => response.OpcNextPage, input => { if (!string.IsNullOrEmpty(input)) { request.Page = input; } return request; }, request => client.ListWorkRequestErrors(request, retryConfiguration, cancellationToken), response => response.WorkRequestErrorCollection.Items )); }
/// <summary> /// Gets the errors for a work request. /// </summary> /// <param name="param"></param> /// <returns></returns> public ListWorkRequestErrorsResponse ListWorkRequestErrors(ListWorkRequestErrorsRequest param) { var uri = new Uri($"{GetEndPoint(CoreServices.WorkRequests, this.Region)}/{param.WorkRequestId}/errors?{param.GetOptionQuery()}"); using (var webResponse = this.RestClient.Get(uri, new HttpRequestHeaderParam { OpcRequestId = param.OpcRequestId })) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = reader.ReadToEnd(); return(new ListWorkRequestErrorsResponse() { Items = JsonSerializer.Deserialize <List <WorkRequestError> >(response), OpcRequestId = webResponse.Headers.Get("opc-request-id"), OpcNextPage = webResponse.Headers.Get("opc-next-page") }); } }
protected override void ProcessRecord() { base.ProcessRecord(); ListWorkRequestErrorsRequest request; try { request = new ListWorkRequestErrorsRequest { WorkRequestId = WorkRequestId, OpcRequestId = OpcRequestId }; response = client.ListWorkRequestErrors(request).GetAwaiter().GetResult(); WriteOutput(response, response.Items, true); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
static void Main(string[] args) { Console.WriteLine("+----------------------------------------+"); Console.WriteLine("| |"); Console.WriteLine("| OCISDK SessionExample |"); Console.WriteLine("| |"); Console.WriteLine("+----------------------------------------+"); string configPath = ".oci/config"; System.OperatingSystem os = System.Environment.OSVersion; // windows if (os.Platform == PlatformID.Win32NT) { string rootPath = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); configPath = $"{rootPath}/{configPath}"; if (!Directory.Exists($"{rootPath}/.oci")) { Directory.CreateDirectory($"{rootPath}/.oci"); } } else { configPath = $"/home/user/{configPath}"; } string profile; ConfigFile configReader; if (File.Exists(configPath)) { Console.Write("Connection ProfileName(Empty Input is DEFAULT): "); profile = Console.ReadLine(); if (string.IsNullOrEmpty(profile)) { profile = "Cloudii"; } // load connection file configReader = ConfigFileReader.Parse(configPath, profile); } else { profile = "DEFAULT"; // create connection file Console.WriteLine("Create connection settings to Oracle Cloud Infrastructure"); Console.Write("TenancyId (Required): "); string tenancyId = OCIDInput(); Console.Write("UserId (Required): "); string userId = OCIDInput(); Console.Write("Fingerprint (Required): "); string fingerprint = KeyInput(); Console.Write("PrivateKeyPath (Required): "); string privateKeyPath = KeyInput(); Console.Write("PrivateKeyPassphrase: "); string privateKeyPassphrase = InputPassword(); string testFileContentsMyProfile = $"[{profile}]\n" + $"tenancy={tenancyId}\n" + $"user={userId}\n" + $"fingerprint={fingerprint}\n" + $"key_file={privateKeyPath}\n" + $"pass_phrase={privateKeyPassphrase}\n"; File.WriteAllText(configPath, testFileContentsMyProfile); configReader = ConfigFileReader.Parse(configPath, profile); } // ClientConfig settings var configSt = new ClientConfigStream(); IOciSession session; using (var st = File.OpenText(configReader.Get("key_file"))) { configSt = new ClientConfigStream { TenancyId = configReader.Get("tenancy"), UserId = configReader.Get("user"), Fingerprint = configReader.Get("fingerprint"), PrivateKey = st, PrivateKeyPassphrase = configReader.Get("pass_phrase"), AccountId = configReader.Get("accountId"), DomainName = configReader.Get("domain_name"), IdentityDomain = configReader.Get("identity_domain"), UserName = configReader.Get("user_name"), Password = configReader.Get("password"), HomeRegion = configReader.Get("home_region") }; session = new OciSession(configSt); } var comClient = session.GetCommercialClient(); var listPurchaseEntitlementsRequest = new ListPurchaseEntitlementsRequest { CompartmentId = configSt.TenancyId }; var purchase = comClient.ListPurchaseEntitlements(listPurchaseEntitlementsRequest); var getServiceEntitlementRegistrationsRequest = new ListServiceEntitlementRegistrationsRequest() { CompartmentId = configSt.TenancyId }; var services = comClient.ListServiceEntitlementRegistrations(getServiceEntitlementRegistrationsRequest); var costClient = session.GetUsageCostsClient(); var getSubscriptionInfoRequest = new GetSubscriptionInfoRequest { TenancyId = configSt.TenancyId }; var subsc = costClient.GetSubscriptionInfo(getSubscriptionInfoRequest); // get Client var identityClient = session.GetIdentityClient(); var getTenancyRequest = new GetTenancyRequest() { TenancyId = configSt.TenancyId }; var getTenacy = identityClient.GetTenancy(getTenancyRequest); Console.WriteLine($"tenantName: {getTenacy.Tenancy.Name}"); // get compute var computeClient = session.GetComputeClient(); IDictionary <string, IDictionary <string, string> > tags = new Dictionary <string, IDictionary <string, string> >(); tags.Add("CostTracking", new Dictionary <string, string> { { "cost-trakcerA", "aaaa" } }); var dbClient = session.GetDatabaseClient(); GetDbSystemRequest getDbSystemRequest = new GetDbSystemRequest() { DbSystemId = "ocid1.dbsystem.oc1.iad.abuwcljrbukbjzlameegvsn3u7qb3qcqvtcdvl74jxfth7xjsya7cxkdpibq" }; var dbSystem = dbClient.GetDbSystem(getDbSystemRequest); UpdateDbSystemRequest updateDbSystemRequest = new UpdateDbSystemRequest() { DbSystemId = "ocid1.dbsystem.oc1.iad.abuwcljrbukbjzlameegvsn3u7qb3qcqvtcdvl74jxfth7xjsya7cxkdpibq", UpdateDbSystemDetails = new OCISDK.Core.Database.Model.UpdateDbSystemDetails() { DefinedTags = tags } }; dbClient.UpdateDbSystem(updateDbSystemRequest); var listCompartmentRequest = new ListCompartmentRequest() { CompartmentId = getTenacy.Tenancy.Id, CompartmentIdInSubtree = true }; var cmparts = identityClient.ListCompartment(listCompartmentRequest); foreach (var com in cmparts.Items) { Console.WriteLine($"compartmentName: {com.Name}"); var listInstanceRequest = new ListInstancesRequest() { CompartmentId = com.Id, Limit = 10, SortOrder = SortOrder.ASC }; var instances = computeClient.ListInstances(listInstanceRequest); foreach (var ins in instances.Items) { Console.WriteLine($"rootCompartmentInstanceName: {ins.DisplayName}"); var workReqestClient = session.GetWorkRequestClient(); var listWorkRequestsRequest = new ListWorkRequestsRequest() { CompartmentId = ins.CompartmentId, ResourceId = ins.Id }; var workreqs = workReqestClient.ListWorkRequests(listWorkRequestsRequest); foreach (var wq in workreqs.Items) { Console.WriteLine($"\tWorkRequest: {wq.OperationType}, state:{wq.Status}"); var getWorkRequestRequest = new GetWorkRequestRequest() { WorkRequestId = wq.Id }; var gw = workReqestClient.GetWorkRequest(getWorkRequestRequest); Console.WriteLine($"\taccepted:{gw.WorkRequest.TimeAccepted}, finished:{gw.WorkRequest.TimeFinished}"); var listWorkRequestErrorsRequest = new ListWorkRequestErrorsRequest() { WorkRequestId = wq.Id, Limit = 100, SortOrder = SortOrder.ASC }; var wqErrors = workReqestClient.ListWorkRequestErrors(listWorkRequestErrorsRequest); foreach (var error in wqErrors.Items) { Console.WriteLine($"\tErrorCode: {error.Code}, ErrorMessage:{error.Message}, ErrorTimeStamp:{error.Timestamp}"); } var listWorkRequestLogsRequest = new ListWorkRequestLogsRequest() { WorkRequestId = wq.Id, Limit = 100, SortOrder = SortOrder.ASC }; var wqLogs = workReqestClient.ListWorkRequestLogs(listWorkRequestLogsRequest); foreach (var log in wqLogs.Items) { Console.WriteLine($"\tLogMessage:{log.Message}, LogTimeStamp:{log.Timestamp}"); } } } } Console.WriteLine("Exit with key press..."); Console.ReadLine(); }