Ejemplo n.º 1
0
        public string GetTasks()
        {
            var baseUri     = $"{INTERNAL_API}{_connectionDetails.SharedSpace}{ANALYTICS_CI_SERVERS}{_connectionDetails.InstanceId}/tasks";
            var queryParams =
                $"self-type={PLUGIN_TYPE}&self-url={HttpUtility.UrlEncode(_connectionDetails.TfsLocation.TrimEnd('/'))}" +
                $"&api-version={API_VERSION}&sdk-version={SDK_VERSION}" +
                $"&plugin-version={PLUGIN_VERSION}" +
                $"&client-id={_connectionDetails.ClientId}";
            ResponseWrapper wrapper = _restConnector.ExecuteGet(baseUri, queryParams, RequestConfiguration.Create().SetTimeout(TASK_POLLING_TIMEOUT));

            return(wrapper.Data);
        }
Ejemplo n.º 2
0
        public EntityListResult <T> Get <T>(IRequestContext context, IList <QueryPhrase> queryPhrases, List <String> fields, int?limit)
            where T : BaseEntity
        {
            String collectionName = GetCollectionName <T>();
            string url            = context.GetPath() + "/" + collectionName;

            String queryString = QueryStringBuilder.BuildQueryString(queryPhrases, fields, null, null, limit, null);

            if (!String.IsNullOrEmpty(queryString))
            {
                url = url + "?" + queryString;
            }

            ResponseWrapper response = rc.ExecuteGet(url);

            if (response.Data != null)
            {
                EntityListResult <T> result = jsonSerializer.Deserialize <EntityListResult <T> >(response.Data);
                return(result);
            }
            return(null);
        }
        public static OctaneApis CreateOctaneConnection(ConnectionDetails connectionDetails)
        {
            Log.Debug($"Validate connection to Octane {connectionDetails.Host} and sharedspace {connectionDetails.SharedSpace}");
            var start         = DateTime.Now;
            var restConnector = new RestConnector();

            //1.validate connectivity
            try
            {
                restConnector.Connect(connectionDetails.Host, new APIKeyConnectionInfo(connectionDetails.ClientId, connectionDetails.ClientSecret));
            }
            catch (Exception ex)
            {
                var    innerException = ExceptionHelper.GetMostInnerException(ex);
                string msg;

                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (innerException.Message.Contains("401"))
                {
                    msg = $"Connection to ALM Octane not authorized, please check ALM Octane client id and secret!";
                }
                else if (innerException.Message.Contains("No connection could be made because the target machine actively refused it"))
                {
                    msg = $"ALM Octane server ({connectionDetails.Host}) could not be reached! Please check ALM Octane is availble on specified port.";
                }
                else if (innerException.Message.Contains("The handshake failed due to an unexpected packet format."))
                {
                    if (connectionDetails.Host.Contains("https"))
                    {
                        msg =
                            $"ALM Octane server ({connectionDetails.Host}) could not be reached! Please check if server supports https connection";
                    }
                    else
                    {
                        msg =
                            $"ALM Octane server ({connectionDetails.Host}) could not be reached (seems like a http/https problem) ! Please check connection url and port";
                    }
                }
                else
                {
                    msg =
                        $"ALM Octane server ({connectionDetails.Host}) could not be reached\n please check ALM Octane location Url\\IP and proxy settings";
                }

                Log.Error(msg, innerException);

                throw new Exception(msg, innerException);
            }

            //2.validate sharedspace exist
            try
            {
                var workspacesUrl = $"/api/shared_spaces/{connectionDetails.SharedSpace}/workspaces?limit=1";
                restConnector.ExecuteGet(workspacesUrl, null);
            }
            catch (Exception ex)
            {
                var msg = $"Could not connect to ALM Octane : sharedspace {connectionDetails.SharedSpace} does not exist";
                Log.Error(msg, ex);
                throw new Exception(msg);
            }

            //validate authorization
            try
            {
                string request = $"/internal-api/shared_spaces/{connectionDetails.SharedSpace}/analytics/ci/servers/connectivity/status";
                restConnector.ExecuteGet(request, null);
            }
            catch (Exception ex)
            {
                if (ex.InnerException is MqmRestException restEx && restEx.StatusCode == HttpStatusCode.Forbidden)
                {
                    const string msg = "Could not connect to ALM Octane : Provided credentials are not sufficient for requested resource";
                    Log.Error(msg);
                    throw new Exception(msg);
                }