Bug 194674 - [prov] [repo] Provide write access to metadata repository
Summary: [prov] [repo] Provide write access to metadata repository
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Incubator (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Prashant Deva CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks: 194675
  Show dependency tree
 
Reported: 2007-06-27 15:42 EDT by Pascal Rapicault CLA
Modified: 2007-09-17 16:23 EDT (History)
6 users (show)

See Also:


Attachments
write api for metadata repository (24.98 KB, patch)
2007-07-09 14:58 EDT, Prashant Deva CLA
no flags Details | Diff
new project to initialize services properly (3.94 KB, application/zip)
2007-07-09 14:59 EDT, Prashant Deva CLA
no flags Details
Made changes as requested (18.06 KB, patch)
2007-07-11 17:28 EDT, Prashant Deva CLA
no flags Details | Diff
Made changes to the writable repo api as requested (9.77 KB, patch)
2007-07-16 19:52 EDT, Prashant Deva CLA
no flags Details | Diff
New patch with changes against the HEAD (12.19 KB, patch)
2007-07-24 09:01 EDT, Prashant Deva CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Rapicault CLA 2007-06-27 15:42:41 EDT
In order to abstract away the implementation details of a particular repository, it would be good to make the metadata repository writtable.
Comment 1 Prashant Deva CLA 2007-06-27 18:42:35 EDT
a simple 'addInstallableUnit' method wont work in the situation when we read some stuff from the repository and * modify  it *  and then write it back.

Here is why -

Say we get the IU 'a' from the repository. Then we modify this IU. Lets call the modfied IU 'a1'. When we write 'a1' back to the repo, it will contain both 'a' and 'a1', which is not what we want. There needs to be some way to say we want to update an IU.

So i propose 2 methods for the IWritableMetadataRepository interface -

void addInstallableUnit(installableUnit); 
void updateInstallableUnit(oldUnit, newUnit);

Note that this will require the classes to hold 2 copies of the IUs, the old one and the new one.

Please give feedback on this.


Comment 2 Pascal Rapicault CLA 2007-06-27 22:21:51 EDT
IUs are not mutable. Therefore if you "modify" an existing IU you need to create a new version of it (there may be exception in dev scenarios).
For example if you have IU A v1.0.0 and you want to change anything in it, you create a new version of the IU called IU A v1.0.1.

Also as a consistency check, the "add" method of the repository should probably signal when an IU being added already exists.

Another thing, we will need the ability to delete stuffs from the repository.
Comment 3 Prashant Deva CLA 2007-06-28 22:41:17 EDT
in the persistencemanager class constructor i am trying to get a reference to IMetadataRepositoriesManager using the following code -


		ServiceReference sr2 = Activator.context.getServiceReference(IMetadataRepositoriesManager.class.getName());
		IMetadataRepositoriesManager mgr = (IMetadataRepositoriesManager) Activator.context.getService(sr2);

but sr2 is always returned as 'null' when i try to run the metadata generator sdk. can someone tell me why this is so? 

i did add a dependency to org.eclipse.equinox.prov.metadata.repository in the plugin.xml.
Comment 4 John Arthorne CLA 2007-06-29 11:34:32 EDT
Note that not all metadata repositories will be writeable. There should either be an isWritable method, or use the same pattern as artifact repository. IArtifactRepo has a method getRepoAsWritable() that returns a sub-interface (IWritableArtifactRepository), and the write methods are defined on this sub-interface.
Comment 5 Pascal Rapicault CLA 2007-06-29 14:37:50 EDT
Prashant, make sure that the org.eclipse.equinox.prov.core or the examplarysetup are started.
Comment 6 Pascal Rapicault CLA 2007-06-29 14:39:07 EDT
John, we were thinking of using the adaptor mechanism to allow for writing capability to be completely separated from the reading one.
Comment 7 Prashant Deva CLA 2007-07-07 21:33:28 EDT
Hi guys,
 I have written the IWritableMetadataRepository interface and made LocalMetadataRepository implement it. I am still in doubt whether to make URLMetadataRepository readable or not since it can be in a remote location where we do not have permission to write.

I have successfully modified PersistenceMetadata to use the new writeable api and it passes all the tests. The amount of actual code written is pretty low but it took me a long time to figure out a lot of stuff and to make it actually pass all the tests.

Please let me know where else in the code you want me to make changes to use the write api. It seems you are using the PersistenceMetadata class everywhere to write to the repository.

Since  I do not have write access to the CVS yet, I will just upload the modified code here on the 9th.
Comment 8 Prashant Deva CLA 2007-07-09 14:58:05 EDT
Created attachment 73364 [details]
write api for metadata repository

here is the code for the write api for metadata repository.
Comment 9 Prashant Deva CLA 2007-07-09 14:59:24 EDT
Created attachment 73366 [details]
new project to initialize services properly

this is a new project i created which just takes care of initializing all the services properly. without this you will get a lot of classnotfound exceptions while running the new code.
Comment 10 Pascal Rapicault CLA 2007-07-09 16:16:53 EDT
I will be looking at the patch shortly and keep you updated in this bug.
Comment 11 Pascal Rapicault CLA 2007-07-09 17:10:14 EDT
I was able to get the review earlier than expected, here are my remarks:

IWrittableMetadataRepository:
- it should not have a setWriteLocation(), since the location to write has been determined when the repository has been created
- add and remove should probably return a boolean
- I'm not sure about save(). On one end it seems to make sense, however then we have to make sure that the changes (removal or addition) are not done visible until save is invoked, which may make consistency across multiple users hard especially when add/remove give feedback. A proposal maybe to have add and remove do batching and block any other write the repo while these operations are performed. Also this problem has probably been addressed in the literature already and it could be good to see what others have done.

To get an IWrittableRepository, the adaptor mechanism should be used rather than casting. This allows for decoupling of the reading and writing code thus allowing lighter weight repo implementation. Also this would give the opportunity to check whether or not a repo is writtable before trying to write in it and fail while saying like it is currently done in MetadataCache#save()

XStreamMetadataManager writeMetadata is not consistent with readMetadata. It should take a stream.
Comment 12 Pascal Rapicault CLA 2007-07-09 18:05:54 EDT
Just to be more clear of what I meant by "to have add and remove do batching", I meant add(InstallableUnit[]) and remove(InstallableUnit[])
Comment 13 Prashant Deva CLA 2007-07-11 17:28:24 EDT
Created attachment 73607 [details]
Made changes as requested

I have made the changes to the writable repo api as requested in the review.
MetadataCache class could not me made to implement the new interface since it requires saving explicitly at the time of a commitoperation event.
Comment 14 Pascal Rapicault CLA 2007-07-13 22:03:30 EDT
I'm a bit disappointed by this patch which did not compile and had not been run (the add method on LocalMetadataRepo was not properly implemented) in conjunction with the other tests.
Moreover you have not addressed the issues around the return value of add and remove.
That said I released a fixed and cleaned up version of the code so that you can more easily work from the repository.
Comment 15 Prashant Deva CLA 2007-07-14 08:51:43 EDT
That is weird, I did a full compile and run before I sent the patch.

I am still not sure whether we should return a false on fail or just crash rightaway. However if you do want want to return a boolean I will implement that.
Comment 16 Pascal Rapicault CLA 2007-07-14 14:05:27 EDT
After some reflection, I think add and remove should return a boolean whose semantics should match Collection.addAll/removeAll.

Also I just discovered that the implementation of LocalMetadataCache no longer discover all the files in the folder indicated as it is indicated in the java doc. 
Comment 17 Pascal Rapicault CLA 2007-07-14 15:42:20 EDT
Could you please also add progress monitors to the add and remove methods.
Comment 18 Prashant Deva CLA 2007-07-16 19:52:29 EDT
Created attachment 73912 [details]
Made changes to the writable repo api as requested

I have made the changes as you requested. Please apply this patch over the current one.
Comment 19 Pascal Rapicault CLA 2007-07-20 14:49:11 EDT
Could you please create the patch against what's in HEAD. I had released the previous one in order for you to work more easily with the repo :)
Thx
Comment 20 Prashant Deva CLA 2007-07-24 09:01:12 EDT
Created attachment 74453 [details]
New patch with changes against the HEAD

Made changes against the HEAD and tested it too.
Comment 21 Jeff McAffer CLA 2007-09-17 16:23:59 EDT
Both artifact and metadata repos have been updated to allow for writable versions.  Overall the approach has been to adapt a given repo to IWritable*Repository.  This in turn allows or adding IUs, descriptors, .. as appropriate.  There is more work to be done in the area of save lifecycle etc but that is for a separate bug.

Closing.