Skip to content

Commit

Permalink
add a few more missing calls to the lock manager, ctron#97
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed May 28, 2015
1 parent c8366ad commit 66a8f71
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public ChannelEntity createChannel ( final String name, final String description
return channel;
}

public void setProvidedMetaData ( final ChannelEntity channel, final Map<MetaKey, String> providedMetaData )
protected void setProvidedMetaData ( final ChannelEntity channel, final Map<MetaKey, String> providedMetaData )
{
if ( providedMetaData == null )
{
Expand All @@ -329,20 +329,22 @@ public void setProvidedMetaData ( final ChannelEntity channel, final Map<MetaKey
@Override
public void updateChannel ( final String channelId, final String name, final String description )
{
final ChannelEntity channel = getCheckedChannel ( channelId );
this.lockManager.modifyRun ( channelId, () -> {
final ChannelEntity channel = getCheckedChannel ( channelId );

if ( "".equals ( name ) )
{
channel.setName ( null );
}
else
{
channel.setName ( name );
}
if ( "".equals ( name ) )
{
channel.setName ( null );
}
else
{
channel.setName ( name );
}

channel.setDescription ( description );
channel.setDescription ( description );

this.em.persist ( channel );
this.em.persist ( channel );
} );
}

@Override
Expand Down Expand Up @@ -698,8 +700,10 @@ public void generateArtifact ( final String id )

testLocked ( ae.getChannel () );

regenerateArtifact ( (GeneratorArtifactEntity)ae, false );
runChannelAggregators ( ae.getChannel () );
this.lockManager.modifyRun ( ae.getChannel ().getId (), () -> {
regenerateArtifact ( (GeneratorArtifactEntity)ae, false );
runChannelAggregators ( ae.getChannel () );
} );
}
catch ( final Exception e )
{
Expand All @@ -719,28 +723,32 @@ public ArtifactInformation deleteArtifact ( final String artifactId )

testLocked ( ae.getChannel () );

if ( !isDeleteable ( ae ) )
{
throw new IllegalStateException ( String.format ( "Unable to delete artifact %s (%s). Artifact might be virtual or generated.", ae.getName (), ae.getId () ) );
}
return this.lockManager.modifyCall ( ae.getChannel ().getId (), () -> {

final SortedMap<MetaKey, String> md = convertMetaData ( ae );
if ( !isDeleteable ( ae ) )
{
throw new IllegalStateException ( String.format ( "Unable to delete artifact %s (%s). Artifact might be virtual or generated.", ae.getName (), ae.getId () ) );
}

this.em.remove ( ae );
this.em.flush ();
final SortedMap<MetaKey, String> md = convertMetaData ( ae );

logger.info ( "Artifact deleted: {}", artifactId );
this.em.remove ( ae );
this.em.flush ();

final ChannelEntity channel = ae.getChannel ();
logger.info ( "Artifact deleted: {}", artifactId );

final RegenerateTracker tracker = new RegenerateTracker ();
runGeneratorTriggers ( tracker, channel, new RemovedEvent ( ae.getId (), md ) );
tracker.process ( this );
final ChannelEntity channel = ae.getChannel ();

// now run the channel aggregator
runChannelAggregators ( channel );
final RegenerateTracker tracker = new RegenerateTracker ();
runGeneratorTriggers ( tracker, channel, new RemovedEvent ( ae.getId (), md ) );
tracker.process ( this );

// now run the channel aggregator
runChannelAggregators ( channel );

return convert ( ae, null );

return convert ( ae, null );
} );
}

private void runGeneratorTriggers ( final RegenerateTracker tracker, final ChannelEntity channel, final Object event )
Expand Down Expand Up @@ -1366,16 +1374,18 @@ public SortedMap<MetaKey, String> getChannelProvidedMetaData ( final String chan

public void clearChannel ( final String channelId )
{
final ChannelEntity channel = getCheckedChannel ( channelId );
this.lockManager.modifyRun ( channelId, () -> {
final ChannelEntity channel = getCheckedChannel ( channelId );

testLocked ( channel );
testLocked ( channel );

// processing by "clear" triggers the entity listeners
// processing by "clear" triggers the entity listeners

channel.getArtifacts ().clear ();
this.em.persist ( channel );
channel.getArtifacts ().clear ();
this.em.persist ( channel );

runChannelAggregators ( channel );
runChannelAggregators ( channel );
} );
}

private static Set<String> expandDependencies ( final Set<String> aspects )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,40 +557,43 @@ public Map<MetaKey, String> applyMetaData ( final String artifactId, final Map<M

testLocked ( artifact.getChannel () );

final Map<MetaKey, String> result = convert ( artifact.getProvidedProperties () );
return this.lockManager.modifyCall ( artifact.getChannel ().getId (), () -> {

// merge
final Map<MetaKey, String> result = convert ( artifact.getProvidedProperties () );

mergeMetaData ( metadata, result );
// merge

// first clear all
mergeMetaData ( metadata, result );

artifact.getProvidedProperties ().clear ();
// first clear all

em.persist ( artifact );
em.flush ();
artifact.getProvidedProperties ().clear ();

// now add the new set
em.persist ( artifact );
em.flush ();

Helper.convertProvidedProperties ( result, artifact, artifact.getProvidedProperties () );
// now add the new set

// store
Helper.convertProvidedProperties ( result, artifact, artifact.getProvidedProperties () );

em.persist ( artifact );
em.flush ();
// store

// recreate virtual artifacts
em.persist ( artifact );
em.flush ();

hi.recreateVirtualArtifacts ( artifact );
// recreate virtual artifacts

// recreate generated artifacts
hi.recreateVirtualArtifacts ( artifact );

if ( artifact instanceof GeneratorArtifactEntity )
{
hi.regenerateArtifact ( (GeneratorArtifactEntity)artifact, true );
}
// recreate generated artifacts

return result;
if ( artifact instanceof GeneratorArtifactEntity )
{
hi.regenerateArtifact ( (GeneratorArtifactEntity)artifact, true );
}

return result;
} );
} );
}

Expand Down Expand Up @@ -700,9 +703,7 @@ public List<Artifact> findByName ( final String channelId, final String artifact
public void clearChannel ( final String channelId )
{
this.lockManager.modifyRun ( channelId, () -> {

doWithHandlerVoid ( hi -> hi.clearChannel ( channelId ) );

} );
}

Expand Down Expand Up @@ -753,30 +754,34 @@ public Collection<DeployGroup> getDeployGroups ( final String channelId )

public void addDeployGroup ( final String channelId, final String groupId )
{
doWithTransactionVoid ( ( em ) -> {
final ChannelEntity channel = getCheckedChannel ( em, channelId );
final DeployGroupEntity group = DeployAuthServiceImpl.getGroupChecked ( em, groupId );
channel.getDeployGroups ().add ( group );
em.persist ( channel );
this.lockManager.modifyRun ( channelId, () -> {
doWithTransactionVoid ( ( em ) -> {
final ChannelEntity channel = getCheckedChannel ( em, channelId );
final DeployGroupEntity group = DeployAuthServiceImpl.getGroupChecked ( em, groupId );
channel.getDeployGroups ().add ( group );
em.persist ( channel );
} );
} );
}

public void removeDeployGroup ( final String channelId, final String groupId )
{
doWithTransactionVoid ( ( em ) -> {
final ChannelEntity channel = getCheckedChannel ( em, channelId );
this.lockManager.modifyRun ( channelId, () -> {
doWithTransactionVoid ( ( em ) -> {
final ChannelEntity channel = getCheckedChannel ( em, channelId );

final Iterator<DeployGroupEntity> i = channel.getDeployGroups ().iterator ();
while ( i.hasNext () )
{
final DeployGroupEntity dg = i.next ();
if ( dg.getId ().equals ( groupId ) )
final Iterator<DeployGroupEntity> i = channel.getDeployGroups ().iterator ();
while ( i.hasNext () )
{
i.remove ();
final DeployGroupEntity dg = i.next ();
if ( dg.getId ().equals ( groupId ) )
{
i.remove ();
}
}
}

em.persist ( channel );
em.persist ( channel );
} );
} );
}

Expand Down

0 comments on commit 66a8f71

Please sign in to comment.