public async Task GetInstanceDataForAlgo()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(algoID);

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.OK);

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Dictionary <string, string> queryParmas = new Dictionary <string, string>()
            {
                { "algoId", postInstanceData.AlgoId },
                { "instanceId", postInstanceData.InstanceId }
            };

            var getInstanceDataResponse = await this.Consumer.ExecuteRequest(url, queryParmas, null, Method.GET);

            Assert.That(getInstanceDataResponse.Status == HttpStatusCode.OK);
            InstanceDataDTO getInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(getInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));
        }
        public async Task PostInstanceDataForAlgo()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(algoID);

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.OK);

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoId, Is.EqualTo((instanceForAlgo.AlgoId)));
            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));


            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);
        }
        public async Task GetAllClientInstanceData()
        {
            MetaDataResponseDTO metadataForUploadedBinary = await UploadBinaryAlgoAndGetResponceDTO();

            string algoID = metadataForUploadedBinary.Id;

            InstanceDataDTO instanceForAlgo = new InstanceDataDTO()
            {
                AlgoId      = algoID,
                HftApiKey   = "key",
                AssetPair   = "BTCUSD",
                TradedAsset = "USD",
                Margin      = "1",
                Volume      = "1"
            };

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.OK);

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.AssetPair, Is.EqualTo(instanceForAlgo.AssetPair));
            Assert.That(postInstanceData.HftApiKey, Is.EqualTo(instanceForAlgo.HftApiKey));
            Assert.That(postInstanceData.TradedAsset, Is.EqualTo(instanceForAlgo.TradedAsset));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Volume), (int)Convert.ToDouble(instanceForAlgo.Volume));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Margin), (int)Convert.ToDouble(instanceForAlgo.Margin));
            Assert.NotNull(postInstanceData.InstanceId);

            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);

            url = ApiPaths.ALGO_STORE_ALGO_GET_ALL_INSTANCE_DATA;

            Dictionary <string, string> queryParmas = new Dictionary <string, string>()
            {
                { "algoId", algoID }
            };

            var responceAllClientInstance = await this.Consumer.ExecuteRequest(url, queryParmas, null, Method.GET);

            Assert.That(responceAllClientInstance.Status, Is.EqualTo(HttpStatusCode.OK));
            Object responceClientGetAll = JsonUtils.DeserializeJson(responceAllClientInstance.ResponseJson);
            List <InstanceDataDTO> listAllClinetObjects = Newtonsoft.Json.JsonConvert.DeserializeObject <List <InstanceDataDTO> >(responceClientGetAll.ToString());
            int mathcedKeysCounter = 0;

            foreach (InstanceDataDTO currentData in listAllClinetObjects)
            {
                bool Exists = currentData.InstanceId.Equals(postInstanceData.InstanceId);
                if (Exists)
                {
                    mathcedKeysCounter++;
                }
            }
            Assert.That(mathcedKeysCounter, Is.EqualTo(1));
        }
        public async Task GetInstanceData()
        {
            MetaDataResponseDTO metadataForUploadedBinary = await UploadBinaryAlgoAndGetResponceDTO();

            string algoID = metadataForUploadedBinary.Id;

            InstanceDataDTO instanceForAlgo = new InstanceDataDTO()
            {
                AlgoId      = algoID,
                HftApiKey   = "key",
                AssetPair   = "BTCUSD",
                TradedAsset = "USD",
                Margin      = "1",
                Volume      = "1"
            };

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoId, Is.EqualTo((instanceForAlgo.AlgoId)));
            Assert.That(postInstanceData.AssetPair, Is.EqualTo((instanceForAlgo.AssetPair)));
            Assert.That(postInstanceData.HftApiKey, Is.EqualTo((instanceForAlgo.HftApiKey)));
            Assert.That(postInstanceData.TradedAsset, Is.EqualTo((instanceForAlgo.TradedAsset)));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Volume), (int)Convert.ToDouble(instanceForAlgo.Volume));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Margin), (int)Convert.ToDouble(instanceForAlgo.Margin));
            Assert.NotNull(postInstanceData.InstanceId);

            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);

            Dictionary <string, string> queryParmas = new Dictionary <string, string>()
            {
                { "algoId", algoID },
                { "instanceId", postInstanceData.InstanceId }
            };

            var instanceDataResponse = await this.Consumer.ExecuteRequest(url, queryParmas, null, Method.GET);

            Assert.That(instanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO returnedClinetInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(instanceDataResponse.ResponseJson);

            Assert.That(returnedClinetInstanceData.AlgoId, Is.EqualTo((postInstanceData.AlgoId)));
            Assert.That(returnedClinetInstanceData.AssetPair, Is.EqualTo((postInstanceData.AssetPair)));
            Assert.That(returnedClinetInstanceData.HftApiKey, Is.EqualTo((postInstanceData.HftApiKey)));
            Assert.That(returnedClinetInstanceData.TradedAsset, Is.EqualTo((postInstanceData.TradedAsset)));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Volume), (int)Convert.ToDouble(postInstanceData.Volume));
            Assert.AreEqual((int)Convert.ToDouble(postInstanceData.Margin), (int)Convert.ToDouble(postInstanceData.Margin));
            Assert.That(returnedClinetInstanceData.InstanceId, Is.EqualTo((postInstanceData.InstanceId)));
        }
        public async Task DeleteAlgoInstance(InstanceDataDTO instanceData)
        {
            CascadeDeleteDTO deleteInstanceDTO = new CascadeDeleteDTO()
            {
                AlgoId       = instanceData.AlgoId,
                AlgoClientId = instanceData.AlgoClientId,
                InstanceId   = instanceData.InstanceId
            };
            var deleteInstanceRequest = await Consumer.ExecuteRequest(ApiPaths.ALGO_STORE_DELETE_INSTANCE, Helpers.EmptyDictionary, JsonUtils.SerializeObject(deleteInstanceDTO), Method.DELETE);

            Assert.That(deleteInstanceRequest.Status, Is.AnyOf(HttpStatusCode.NoContent, HttpStatusCode.NotFound));
        }
        public async Task DeployInstance(InstanceDataDTO instanceData)
        {
            DeployBinaryDTO deploy = new DeployBinaryDTO()
            {
                AlgoId     = instanceData.AlgoId,
                InstanceId = instanceData.InstanceId,
            };

            var deployBynaryResponse = await Consumer.ExecuteRequest(ApiPaths.ALGO_STORE_DEPLOY_BINARY, Helpers.EmptyDictionary, JsonUtils.SerializeObject(deploy), Method.POST);

            message = $"POST {ApiPaths.ALGO_STORE_DEPLOY_BINARY} returned status: {deployBynaryResponse.Status} and response: {deployBynaryResponse.ResponseJson}. Expected: {HttpStatusCode.OK}";
            Assert.That(deployBynaryResponse.Status, Is.EqualTo(HttpStatusCode.OK));
        }
Ejemplo n.º 7
0
        public async Task CreateAlgoAndStartInstance(int numberOfInstances)
        {
            for (int i = 0; i < numberOfInstances; i++)
            {
                // Create algo
                algoData = await CreateAlgo();

                // Create instance
                InstanceDataDTO instanceData = await SaveInstance(algoData, instanceType);

                postInstanceData = instanceData;
            }
        }
        public async Task GetAllClientInstanceData()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(algoID);

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.OK);

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));

            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);

            url = ApiPaths.ALGO_STORE_ALGO_GET_ALL_INSTANCE_DATA;

            Dictionary <string, string> queryParmas = new Dictionary <string, string>()
            {
                { "algoId", algoID }
            };

            var responceAllClientInstance = await this.Consumer.ExecuteRequest(url, queryParmas, null, Method.GET);

            Assert.That(responceAllClientInstance.Status, Is.EqualTo(HttpStatusCode.OK));
            Object responceClientGetAll = JsonUtils.DeserializeJson(responceAllClientInstance.ResponseJson);
            List <InstanceDataDTO> listAllClinetObjects = Newtonsoft.Json.JsonConvert.DeserializeObject <List <InstanceDataDTO> >(responceClientGetAll.ToString());
            int mathcedKeysCounter = 0;

            foreach (InstanceDataDTO currentData in listAllClinetObjects)
            {
                bool Exists = currentData.InstanceId.Equals(postInstanceData.InstanceId);
                if (Exists)
                {
                    mathcedKeysCounter++;
                }
            }
            Assert.That(mathcedKeysCounter, Is.EqualTo(1));
        }
        public async Task <StatisticsDTO> GetStatisticsResponseAsync(InstanceDataDTO instanceData, int waitTime = 10000)
        {
            // Build statistics endpoint query param dictionary
            Dictionary <string, string> statisticsQueryParams = new Dictionary <string, string>()
            {
                { "instanceId", instanceData.InstanceId }
            };

            Wait.ForPredefinedTime(waitTime); // Wait for some trades to be done
            Response statisticsResponse = await Consumer.ExecuteRequest(statisticsPath, statisticsQueryParams, null, Method.GET);

            Assert.That(statisticsResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            return(JsonUtils.DeserializeJson <StatisticsDTO>(statisticsResponse.ResponseJson));
        }
Ejemplo n.º 10
0
        public async Task PostInvalidAlgoId()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO("123 invalid algo id");

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.NotFound);
        }
        public async Task <string> GetInstanceTailLogFromApi(InstanceDataDTO instanceData, int messagesToGet = 100)
        {
            // Build params
            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "Tail", messagesToGet.ToString() },
                { "AlgoId", instanceData.AlgoId },
                { "InstanceId", instanceData.InstanceId },
                { "AlgoClientId", instanceData.AlgoClientId }
            };

            var tailLogRequest = await Consumer.ExecuteRequest(ApiPaths.ALGO_STORE_ALGO_INSTANCE_LOG, queryParams, null, Method.GET);

            Assert.That(tailLogRequest.Status, Is.EqualTo(HttpStatusCode.OK));

            return(tailLogRequest.ResponseJson);
        }
Ejemplo n.º 12
0
        public async Task PostInstanceDataOnlyWithZeroMArginZeroVolume()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(algoID);

            // set custrom data here for the metadata traded 0 margin 0 volume

            string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == HttpStatusCode.NotFound);
        }
        public async Task <List <TailLogDTO> > GetInstanceTailLogFromLoggingService(InstanceDataDTO instanceData, int messagesToGet = 100)
        {
            var tailLogUrl = $"{BaseUrl.AlgoStoreLoggingApiBaseUrl}{ApiPaths.ALGO_STORE_LOGGING_API_TAIL_LOG}";

            // Get instance token
            var token = await GetInstanceAuthToken(instanceData.InstanceId);

            // Build params
            Dictionary <string, string> queryParams = new Dictionary <string, string>();

            queryParams.Add("InstanceId", instanceData.InstanceId);
            queryParams.Add("Tail", messagesToGet.ToString());

            var tailLogRequest = await Consumer.ExecuteRequestCustomEndpoint(tailLogUrl, queryParams, null, Method.GET, authToken : token);

            Assert.That(tailLogRequest.Status, Is.EqualTo(HttpStatusCode.OK));

            return(JsonUtils.DeserializeJson <List <TailLogDTO> >(tailLogRequest.ResponseJson));
        }
Ejemplo n.º 14
0
        public async Task EditInstanceDataForAlgo()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            //InstanceDataDTO instanceForAlgo = GetPopulatedInstanceDataDTO.returnInstanceDataDTO(algoID);

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(algoInstanceDataPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));

            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);
            InstanceDataDTO instanceForAlgoEdit = postInstanceData;

            postInstanceData.InstanceName = "EditedTest";

            var postInstanceDataResponseEdit = await this.Consumer.ExecuteRequest(algoInstanceDataPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgoEdit), Method.POST);

            Assert.That(postInstanceDataResponseEdit.Status, Is.EqualTo(HttpStatusCode.OK));
            InstanceDataDTO postInstanceDataEdit = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponseEdit.ResponseJson);

            Assert.That(postInstanceDataEdit.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceDataEdit.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceDataEdit.InstanceId, Is.EqualTo(instanceDataEntityExists.Id));
            Assert.That(postInstanceDataEdit.InstanceName, Is.EqualTo("EditedTest"));

            ClientInstanceEntity instanceDataEntityExistsEdit = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceDataEdit.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExistsEdit);
        }
Ejemplo n.º 15
0
        public async Task GetInstanceData()
        {
            UploadStringDTO metadataForUploadedBinary = await UploadStringAlgo();

            string algoID = metadataForUploadedBinary.AlgoId;

            //InstanceDataDTO instanceForAlgo = GetPopulatedInstanceDataDTO.returnInstanceDataDTO(algoID);

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(algoInstanceDataPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));

            ClientInstanceEntity instanceDataEntityExists = await ClientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);

            Dictionary <string, string> queryParmas = new Dictionary <string, string>()
            {
                { "algoId", algoID },
                { "instanceId", postInstanceData.InstanceId }
            };

            var instanceDataResponse = await this.Consumer.ExecuteRequest(algoInstanceDataPath, queryParmas, null, Method.GET);

            Assert.That(instanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO returnedClinetInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(instanceDataResponse.ResponseJson);

            Assert.That(postInstanceData.AlgoClientId, Is.EqualTo(instanceForAlgo.AlgoClientId));
            Assert.That(postInstanceData.AlgoId, Is.EqualTo(instanceForAlgo.AlgoId));
            Assert.That(postInstanceData.InstanceName, Is.EqualTo(instanceForAlgo.InstanceName));
        }
        public async Task StopAlgoInstance(InstanceDataDTO instanceData)
        {
            StopBinaryDTO stopAlgo = new StopBinaryDTO()
            {
                AlgoId     = instanceData.AlgoId,
                InstanceId = instanceData.InstanceId
            };
            var stopAlgoRequest = await Consumer.ExecuteRequest(stopAlgoPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

            StopBinaryResponseDTO stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(stopAlgoRequest.ResponseJson);

            int retryCounter = 1;

            while (stopAlgoResponce != null && stopAlgoResponce.Status != null && !stopAlgoResponce.Status.Equals("Stopped") && retryCounter <= 30)
            {
                System.Threading.Thread.Sleep(10000);
                stopAlgoRequest = await Consumer.ExecuteRequest(stopAlgoPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

                stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(stopAlgoRequest.ResponseJson);

                retryCounter++;
            }
        }
Ejemplo n.º 17
0
        public async Task <List <BuilInitialDataObjectDTO> > UploadSomeBaseMetaData(int nuberDto)
        {
            string                     url                  = ApiPaths.ALGO_STORE_METADATA;
            List <MetaDataDTO>         metadataList         = new List <MetaDataDTO>();
            List <MetaDataResponseDTO> responceMetadataList = new List <MetaDataResponseDTO>();

            for (int i = 0; i < nuberDto; i++)
            {
                MetaDataDTO metadata = new MetaDataDTO()
                {
                    Name        = Helpers.RandomString(13),
                    Description = Helpers.RandomString(13)
                };
                metadataList.Add(metadata);
            }

            foreach (var metadata in metadataList)
            {
                var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(metadata), Method.POST);

                MetaDataResponseDTO responceMetaData = JsonUtils.DeserializeJson <MetaDataResponseDTO>(response.ResponseJson);
                responceMetadataList.Add(responceMetaData);
            }

            for (int i = 0; i < nuberDto; i++)
            {
                url = ApiPaths.ALGO_STORE_UPLOAD_STRING;

                UploadStringDTO stringDTO = new UploadStringDTO()
                {
                    AlgoId = responceMetadataList[i].Id,
                    Data   = this.CSharpAlgoString
                };

                var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stringDTO), Method.POST);

                Assert.True(response.Status == System.Net.HttpStatusCode.NoContent);

                GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

                InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(stringDTO.AlgoId);

                url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

                var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

                Assert.That(postInstanceDataResponse.Status == System.Net.HttpStatusCode.OK);

                InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

                url = ApiPaths.ALGO_STORE_DEPLOY_BINARY;

                DeployBinaryDTO deploy = new DeployBinaryDTO()
                {
                    AlgoId     = stringDTO.AlgoId,
                    InstanceId = postInstanceData.InstanceId,
                };

                var deployBynaryResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(deploy), Method.POST);

                Assert.That(postInstanceDataResponse.Status == System.Net.HttpStatusCode.OK);

                BuilInitialDataObjectDTO tempDataDTO = new BuilInitialDataObjectDTO()
                {
                    AlgoId      = stringDTO.AlgoId,
                    InstanceId  = postInstanceData.InstanceId,
                    Name        = responceMetadataList[i].Name,
                    Description = responceMetadataList[i].Description
                };

                initialDTOObjectsList.Add(tempDataDTO);
            }

            return(initialDTOObjectsList);
        }
 public static async Task <ClientInstanceEntity> GetStoppingEntityForInstance(GenericRepository <ClientInstanceEntity, IClientInstance> clientInstanceRepository, InstanceDataDTO postInstanceData)
 {
     return(await clientInstanceRepository.TryGetAsync(t => t.InstanceId == postInstanceData.InstanceId) as ClientInstanceEntity);
 }
Ejemplo n.º 19
0
        public static async Task WaitAlgoToStart(GenericRepository <ClientInstanceEntity, IClientInstance> clientInstanceRepository, InstanceDataDTO postInstanceData)
        {
            ClientInstanceEntity instanceDataEntityExists = await clientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

            Assert.NotNull(instanceDataEntityExists);

            // Wait up to 3 minutes for the algo to be started
            int count = 45;

            while (instanceDataEntityExists.AlgoInstanceStatusValue != "Started" && count > 1) // TODO: Update when a health check endpoint is created
            {
                Wait.ForPredefinedTime(5000);                                                  // Wait for five secodns before getting the algo instance data again
                instanceDataEntityExists = await clientInstanceRepository.TryGetAsync(t => t.Id == postInstanceData.InstanceId) as ClientInstanceEntity;

                count--;
            }
        }
        public async Task DeployStringAlgo()
        {
            string url = ApiPaths.ALGO_STORE_METADATA;

            MetaDataDTO metadata = new MetaDataDTO()
            {
                Name        = Helpers.RandomString(13),
                Description = Helpers.RandomString(13)
            };

            var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(metadata), Method.POST);

            MetaDataResponseDTO responceMetaData = JsonUtils.DeserializeJson <MetaDataResponseDTO>(response.ResponseJson);

            url = ApiPaths.ALGO_STORE_UPLOAD_STRING;

            UploadStringDTO stringDTO = new UploadStringDTO()
            {
                AlgoId = responceMetaData.Id,
                Data   = this.CSharpAlgoString
            };

            var responsetemp = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stringDTO), Method.POST);

            Assert.True(responsetemp.Status == System.Net.HttpStatusCode.NoContent);

            GetPopulatedInstanceDataDTO getinstanceAlgo = new GetPopulatedInstanceDataDTO();

            InstanceDataDTO instanceForAlgo = getinstanceAlgo.returnInstanceDataDTO(stringDTO.AlgoId);

            url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status == System.Net.HttpStatusCode.OK);

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            url = ApiPaths.ALGO_STORE_DEPLOY_BINARY;

            DeployBinaryDTO deploy = new DeployBinaryDTO()
            {
                AlgoId     = stringDTO.AlgoId,
                InstanceId = postInstanceData.InstanceId,
            };

            var deployBynaryResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(deploy), Method.POST);

            Assert.That(postInstanceDataResponse.Status == System.Net.HttpStatusCode.OK);

            url = ApiPaths.ALGO_STORE_CASCADE_DELETE;
            int retryCounter = 0;

            CascadeDeleteDTO editMetaData = new CascadeDeleteDTO()
            {
                AlgoId     = postInstanceData.AlgoId,
                InstanceId = postInstanceData.InstanceId
            };
            var responceCascadeDelete = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(editMetaData), Method.POST);

            // Currently we can not send cascade delete to kubernatees if he has not build the algo before that thorus not found and we leave data

            while (responceCascadeDelete.Status.Equals(System.Net.HttpStatusCode.NotFound) && retryCounter <= 30)
            {
                System.Threading.Thread.Sleep(10000);
                responceCascadeDelete = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(editMetaData), Method.POST);

                retryCounter++;
            }

            Assert.That(responceCascadeDelete.Status == System.Net.HttpStatusCode.NoContent);
        }
Ejemplo n.º 21
0
        public async Task StopAlgo()
        {
            string url = ApiPaths.ALGO_STORE_METADATA;

            MetaDataDTO metadata = new MetaDataDTO()
            {
                Name        = Helpers.RandomString(13),
                Description = Helpers.RandomString(13)
            };

            var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(metadata), Method.POST);

            MetaDataResponseDTO responceMetaData = JsonUtils.DeserializeJson <MetaDataResponseDTO>(response.ResponseJson);

            url = ApiPaths.ALGO_STORE_UPLOAD_STRING;

            UploadStringDTO stringDTO = new UploadStringDTO()
            {
                AlgoId = responceMetaData.Id,
                Data   = this.CSharpAlgoString
            };

            var responsetemp = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stringDTO), Method.POST);

            Assert.That(responsetemp.Status, Is.EqualTo(HttpStatusCode.NoContent));

            //InstanceDataDTO instanceForAlgo = GetPopulatedInstanceDataDTO.returnInstanceDataDTO(stringDTO.AlgoId);

            url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA;

            var postInstanceDataResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST);

            Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            InstanceDataDTO postInstanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(postInstanceDataResponse.ResponseJson);

            url = ApiPaths.ALGO_STORE_DEPLOY_BINARY;

            DeployBinaryDTO deploy = new DeployBinaryDTO()
            {
                AlgoId     = stringDTO.AlgoId,
                InstanceId = postInstanceData.InstanceId,
            };

            var deployBynaryResponse = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(deploy), Method.POST);

            Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            url = ApiPaths.ALGO_STORE_ALGO_STOP;
            int retryCounter = 0;

            StopBinaryDTO stopAlgo = new StopBinaryDTO()
            {
                AlgoId     = postInstanceData.AlgoId,
                InstanceId = postInstanceData.InstanceId
            };
            var responceCascadeDelete = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

            StopBinaryResponseDTO stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(responceCascadeDelete.ResponseJson);;

            while ((stopAlgoResponce.Status.Equals("Deploying") || stopAlgoResponce.Status.Equals("Started")) && retryCounter <= 30)
            {
                System.Threading.Thread.Sleep(10000);
                responceCascadeDelete = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

                stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(responceCascadeDelete.ResponseJson);

                retryCounter++;
            }

            Assert.That(responceCascadeDelete.Status, Is.EqualTo(HttpStatusCode.OK));

            Assert.That(stopAlgoResponce.Status, Is.EqualTo("Stopped"));

            ClientInstanceEntity algoInstanceEntitiy = await ClientInstanceRepository.TryGetAsync(t => t.PartitionKey == "algo_" + stringDTO.AlgoId) as ClientInstanceEntity;

            Assert.That(algoInstanceEntitiy.AlgoInstanceStatusValue, Is.EqualTo("Stopped"));
        }