geo_coding_service = $geo_coding_service; } protected function clearCollections(ICompanyService &$cloud){ parent::clearCollections($cloud); if($cloud instanceof ICloudService){ $cloud->clearDataCenterRegions(); $cloud->clearDataCentersLocations(); } } protected function updateCollections(ICompanyService &$cloud, array $data){ parent::updateCollections($cloud, $data); // add data centers locations if(array_key_exists('data_centers',$data) && is_array($data['data_centers'])){ $data_centers_data = $data['data_centers']; if(!array_key_exists('regions',$data_centers_data) || !is_array($data_centers_data['regions'])) return $this->validationError(array(array('message'=>'missing regions on data_centers!.'))); if(!array_key_exists('locations',$data_centers_data) || !is_array($data_centers_data['locations'])) return $this->validationError(array(array('message'=>'missing locations on data_centers!.'))); $regions_data = $data_centers_data['regions']; foreach($regions_data as $region_data){ $this->addDataCenterRegion($region_data, $cloud); } $locations_data = $data_centers_data['locations']; foreach($locations_data as $location_data){ $this->addDataCenterLocation($location_data, $cloud); } } } protected function addDataCenterRegion(array $region_data, ICloudService $cloud){ $validator = $this->validator_factory->buildValidatorForDataCenterRegion($region_data); if ($validator->fails()) { return $this->validationError($validator->messages()); } $region = $this->factory->buildDataCenterRegion($region_data['name'],$region_data['color'],$region_data['endpoint']); $cloud->addDataCenterRegion($region); $region->setCloud($cloud); } protected function addDataCenterLocation(array $location_data, ICloudService $cloud){ //check location coordinates... $validator = $this->validator_factory->buildValidatorForDataCenterLocation($location_data); if ($validator->fails()) { return $this->validationError($validator->messages()); } //list($lat,$lng) = $this->geo_coding_service->getCityCoordinates($location_data['city'],$location_data['country']); $location = $this->factory->buildDataCenterLocation( $location_data['city'], $location_data['state'], $location_data['country'], (float)$location_data['lat'], (float)$location_data['lng'], $cloud->getDataCenterRegion($location_data['region']) ); if(array_key_exists('availability_zones',$location_data) && is_array($location_data['availability_zones'])){ foreach($location_data['availability_zones'] as $az_data){ $az = $this->factory->buildAZ($az_data['name'],$location); $location->addAvailabilityZone($az); $az->setLocation($location); } } $cloud->addDataCenterLocation($location); $location->setCloudService($cloud); return $cloud; } /** * @param array $capability_data * @param IOpenStackImplementation $company_service * @throws NotFoundEntityException * @throws NonSupportedComponent */ protected function addCapability(array $capability_data, IOpenStackImplementation $company_service){ $validator = $this->validator_factory->buildValidatorForCapability($capability_data); if ($validator->fails()) { return $this->validationError($validator->messages()); } $component = $this->component_repository->getById(intval($capability_data['component_id'])); if(!$component) throw new NotFoundEntityException('OpenStackComponent',sprintf('id %',intval($capability_data['component_id']))); $release = $this->release_repository->getById(intval($capability_data['release_id'])); if(!$release) throw new NotFoundEntityException('OpenStackRelease',sprintf('id %',intval($capability_data['release_id']))); if(!$release->supportsComponent($component->getCodeName())) throw new NonSupportedComponent($release,$component); $supported_version = null; if($component->getSupportsVersioning()){ $version = $this->api_version_repository->getById(intval($capability_data['version_id'])); if(!$version) throw new NotFoundEntityException('OpenStackApiVersion',sprintf('id %',intval($capability_data['version_id']))); $supported_version = $release->supportsApiVersion($version); } else{ $supported_version = $this->supported_version_repository->getByReleaseAndComponentAndApiVersion(intval($capability_data['release_id']),intval($capability_data['component_id']),0); } if(!$supported_version) throw new NotFoundEntityException('OpenStackReleaseSupportedVersion',''); $service = $this->factory->buildCapability(intval($capability_data['coverage']),$supported_version, $company_service); if(array_key_exists('pricing_schemas',$capability_data) && is_array($capability_data['pricing_schemas'])){ foreach($capability_data['pricing_schemas'] as $ps){ $service->addPricingSchema($this->factory->buildPricingSchemaById(intval($ps))); } } $this->registerCapability($company_service, $service); } }