Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.21.21] - 2024-05-03
- Fix "Unable to verify target bucket for Remote Catalog: Not Found. Object could not be found" error
- Fixed caching to prevent unnecessary refreshing of bucket data.
  • Loading branch information
Unity Technologies committed May 3, 2024
1 parent d7b49ef commit 655b7ff
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 73 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.21.21] - 2024-05-03
- Fix "Unable to verify target bucket for Remote Catalog: Not Found. Object could not be found" error
- Fixed caching to prevent unnecessary refreshing of bucket data.

## [1.21.20] - 2024-02-08
- Fixed an issue where scene InternalId collisions were very likely when using dynamic internal asset naming
- Fixed catalogs to use back slashes rather than forward slashes for android builds.
Expand Down
42 changes: 31 additions & 11 deletions Editor/Build/CcdBuildEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ internal async Task<bool> verifyTargetBucket(AddressableAssetSettings settings,
return true;
}

if (settings.m_CcdManagedData.IsConfigured())
{
// this has been configured by a previous run
return true;
}


// existing automatic bucket loaded from cache
var bucketIdVariable = dataSource
Expand All @@ -450,11 +456,15 @@ internal async Task<bool> verifyTargetBucket(AddressableAssetSettings settings,
}

// otherwise try to create
CcdManagement.SetEnvironmentId(settings.m_CcdManagedData.EnvironmentId);
await CreateManagedBucket(EditorUserBuildSettings.activeBuildTarget.ToString());
// we created a bucket so refresh our data sources so we ensure they're up to date
await RefreshDataSources();

var environmentId = ProfileDataSourceSettings.GetSettings().GetEnvironmentId(settings.profileSettings, settings.activeProfileId);
CcdManagement.SetEnvironmentId(environmentId); // this should be getting the value from the active profile
var ccdBucket = await CreateManagedBucket(EditorUserBuildSettings.activeBuildTarget.ToString());
if (ccdBucket == null) {
// the bucket already exists, we shouldn't be here if refresh was called
ccdBucket = await GetExistingManagedBucket();
}
var environmentName = ProfileDataSourceSettings.GetSettings().GetEnvironmentName(settings.profileSettings, settings.activeProfileId);
ProfileDataSourceSettings.AddGroupTypeForRemoteBucket(CloudProjectSettings.projectId, environmentId, environmentName, ccdBucket, new List<CcdBadge>());
PopulateCcdManagedData(settings, settings.activeProfileId);

// I should put this value into the data source list
Expand Down Expand Up @@ -747,12 +757,16 @@ internal ProfileGroupType GetDataSource(AddressableAssetSettings settings, strin
return groupType;
}

var groupTypes = ProfileDataSourceSettings.GetSettings().GetGroupTypesByPrefix(string.Join(
var environmentId = ProfileDataSourceSettings.GetSettings().GetEnvironmentId(settings.profileSettings, settings.activeProfileId);
// if we haven't setup an automatic group since refresh we do it here
IEnumerable<ProfileGroupType> groupTypes = ProfileDataSourceSettings.GetSettings().GetGroupTypesByPrefix(string.Join(
ProfileGroupType.k_PrefixSeparator.ToString(), "CCD", CloudProjectSettings.projectId,
ProfileDataSourceSettings.GetSettings().GetEnvironmentId(settings.profileSettings, settings.activeProfileId)));
// if we have setup an automatic group we load it here
groupTypes = groupTypes.Concat(ProfileDataSourceSettings.GetSettings().GetGroupTypesByPrefix(AddressableAssetSettings.CcdManagerGroupTypePrefix));
var automaticGroupType = groupTypes.FirstOrDefault(gt =>
gt.GetVariableBySuffix($"{nameof(CcdBucket)}{nameof(CcdBucket.Name)}").Value ==
EditorUserBuildSettings.activeBuildTarget.ToString());
gt.GetVariableBySuffix($"{nameof(CcdBucket)}{nameof(CcdBucket.Name)}")?.Value == EditorUserBuildSettings.activeBuildTarget.ToString()
&& gt.GetVariableBySuffix($"{nameof(ProfileDataSourceSettings.Environment)}{nameof(ProfileDataSourceSettings.Environment.id)}")?.Value == environmentId);
if (automaticGroupType == null)
{
// the bucket does not yet exist
Expand Down Expand Up @@ -838,9 +852,7 @@ async Task<CcdBucket> CreateManagedBucket(string bucketName)
{
if (e.ErrorCode == CcdManagementErrorCodes.AlreadyExists)
{
var buckets = await ProfileDataSourceSettings.GetAllBucketsAsync();
ccdBucket = buckets.First(bucket =>
bucket.Value.Name == EditorUserBuildSettings.activeBuildTarget.ToString()).Value;
return null;
}
else
{
Expand All @@ -850,6 +862,14 @@ async Task<CcdBucket> CreateManagedBucket(string bucketName)
return ccdBucket;
}

async Task<CcdBucket> GetExistingManagedBucket()
{
var buckets = await ProfileDataSourceSettings.GetAllBucketsAsync();
var ccdBucket = buckets.First(bucket =>
bucket.Value.Name == EditorUserBuildSettings.activeBuildTarget.ToString()).Value;
return ccdBucket;
}

async Task<CcdEntry> GetEntryByPath(ICcdManagementServiceSdk api, Guid bucketId, string path)
{
CcdEntry ccdEntry = null;
Expand Down
58 changes: 32 additions & 26 deletions Editor/Settings/ProfileDataSourceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static async Task<List<ProfileGroupType>> UpdateCCDDataSourcesAsync(strin
Addressables.Log("Syncing CCD Environments, Buckets, and Badges.");
}

var profileGroupTypes = new List<ProfileGroupType>();
settings.profileGroupTypes.Clear();

var environments = await GetEnvironments();

Expand All @@ -264,7 +264,7 @@ public static async Task<List<ProfileGroupType>> UpdateCCDDataSourcesAsync(strin
EditorUtility.DisplayProgressBar("Syncing Profile Data Sources", "Fetching Environments", 0);
Addressables.Log($"Successfully fetched {environments.Count} environments.");
}
profileGroupTypes.AddRange(CreateDefaultGroupTypes());
settings.profileGroupTypes.AddRange(CreateDefaultGroupTypes());

try
{
Expand All @@ -284,35 +284,12 @@ public static async Task<List<ProfileGroupType>> UpdateCCDDataSourcesAsync(strin
}

var badges = await GetAllBadgesAsync(bucket.Id.ToString());
if (badges.Count == 0) badges.Add(new CcdBadge(name: "latest"));
foreach (var badge in badges)
{
var groupType =
new ProfileGroupType($"CCD{ProfileGroupType.k_PrefixSeparator}{projectId}{ProfileGroupType.k_PrefixSeparator}{environment.id}{ProfileGroupType.k_PrefixSeparator}{bucket.Id}{ProfileGroupType.k_PrefixSeparator}{badge.Name}");
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Name)}", bucket.Name));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Id)}", bucket.Id.ToString()));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBadge)}{nameof(CcdBadge.Name)}", badge.Name));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(nameof(CcdBucket.Attributes.PromoteOnly), bucket.Attributes.PromoteOnly.ToString()));

//Adding environment stub here
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(Environment)}{nameof(Environment.name)}", environment.name));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(Environment)}{nameof(Environment.id)}", environment.id));

string buildPath = $"{AddressableAssetSettings.kCCDBuildDataPath}/{environment.id}/{bucket.Id}/{badge.Name}";
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kBuildPath, buildPath));

string loadPath =
$"https://{projectId}{m_CcdClientBasePath}/client_api/v1/environments/{environment.name}/buckets/{bucket.Id}/release_by_badge/{badge.Name}/entry_by_path/content/?path=";
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kLoadPath, loadPath));

profileGroupTypes.Add(groupType);
}
AddGroupTypeForRemoteBucket(projectId, environment.id, environment.name, bucket, badges);
bucketProgress++;
}
envProgress++;
}

settings.profileGroupTypes = profileGroupTypes;
settings.environments = environments.ToList();
if (showInfoLog) Addressables.Log("Successfully synced CCD Buckets and Badges.");
EditorUtility.SetDirty(settings);
Expand All @@ -330,6 +307,35 @@ public static async Task<List<ProfileGroupType>> UpdateCCDDataSourcesAsync(strin
return settings.profileGroupTypes;
}

internal static void AddGroupTypeForRemoteBucket(string projectId, string environmentId, string environmentName, CcdBucket bucket, List<CcdBadge> badges)
{
var settings = GetSettings();
if (badges.Count == 0) badges.Add(new CcdBadge(name: "latest"));
foreach (var badge in badges)
{
var groupType =
new ProfileGroupType(
$"CCD{ProfileGroupType.k_PrefixSeparator}{projectId}{ProfileGroupType.k_PrefixSeparator}{environmentId}{ProfileGroupType.k_PrefixSeparator}{bucket.Id}{ProfileGroupType.k_PrefixSeparator}{badge.Name}");
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Name)}", bucket.Name));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Id)}", bucket.Id.ToString()));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBadge)}{nameof(CcdBadge.Name)}", badge.Name));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(nameof(CcdBucket.Attributes.PromoteOnly), bucket.Attributes.PromoteOnly.ToString()));

//Adding environment stub here
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(Environment)}{nameof(Environment.name)}", environmentName));
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(Environment)}{nameof(Environment.id)}", environmentId));

string buildPath = $"{AddressableAssetSettings.kCCDBuildDataPath}/{environmentId}/{bucket.Id}/{badge.Name}";
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kBuildPath, buildPath));

string loadPath =
$"https://{projectId}{m_CcdClientBasePath}/client_api/v1/environments/{environmentName}/buckets/{bucket.Id}/release_by_badge/{badge.Name}/entry_by_path/content/?path=";
groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kLoadPath, loadPath));

settings.profileGroupTypes.Add(groupType);
}
}

internal static async Task<Dictionary<Guid, CcdBucket>> GetAllBucketsAsync()
{
int page = 1;
Expand Down
Loading

0 comments on commit 655b7ff

Please sign in to comment.