Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import org.apache.log4j.Logger;
4
 
5
import com.erggroup.buildtool.smtp.Smtpsend;
6
 
7
import java.sql.SQLException;
8
import java.util.Iterator;
9
import java.util.Vector;
10
 
11
/**entity class holding build exclusion data
12
 */
13
public class BuildExclusion
14
{
15
  /**Logger
16
   * @attribute
17
   */
18
  private static final Logger mLogger = Logger.getLogger(BuildExclusion.class);
19
 
20
  /**identifier
21
   * @attribute
22
   */
23
  private int mId;
24
 
25
  /**root identifier
26
   * @attribute
27
   */
28
  private int mRootId;
29
 
30
  /**root cause
31
   * @attribute
32
   */
33
  private String mRootCause;
34
 
35
  /**in terms of the mChangeType Package field,
36
   * when true indicates the package has not changed, its dependencies potentially have
37
   * in terms of the mRippleField Package field,
38
   * when true indicates the build number will be incremented
39
   * @attribute
40
   */
41
  private boolean mProcessed = false;
42
 
43
  /**constructor
44
   */
45
  public BuildExclusion(int identifier, int rootIdentifier, String rootCause)
46
  {
47
    mLogger.debug("BuildExclusion");
48
    mId = identifier;
868 mhunt 49
    mRootId = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 50
    mRootCause = rootCause;
51
  }
52
 
53
  /**sets mProcessed true
54
   */
55
  void process()
56
  {
57
    mLogger.debug("process " + mId);
58
    mProcessed = true;
59
  }
60
 
61
  /**accessor
62
   */
63
  boolean isProcessed()
64
  {
65
    mLogger.debug("isProcessed " + mId);
66
    mLogger.info("isProcessed returned " + mProcessed);
67
    return mProcessed;
68
  }
69
 
70
  /**return true if all attributes match
71
   */
72
  boolean compare( int identifier, int rootIdentifier, String rootCause)
73
  {
74
    mLogger.debug("compare " + mId + ", " + identifier + ", " + rootIdentifier + ", " + rootCause);
75
    boolean retVal = false;
868 mhunt 76
    rootIdentifier = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 77
 
78
    if ( mRootCause == null )
79
    {
80
      if ( mId == identifier && mRootId == rootIdentifier && rootCause == null )
81
      {
82
        retVal = true;
83
      }
84
    }
85
    else
86
    {
87
      if ( mId == identifier && mRootId == rootIdentifier && mRootCause.compareTo(rootCause) == 0 )
88
      {
89
        retVal = true;
90
      }
91
    }
92
 
868 mhunt 93
    mLogger.info("compare returned " + retVal);
866 mhunt 94
    return retVal;
95
  }
96
 
97
  /**return true if mId attribute matches
98
   */
99
  boolean compare( int identifier )
100
  {
101
    mLogger.debug("compare " + mId + ", " + identifier);
102
    boolean retVal = false;
103
 
104
    if ( mId == identifier )
105
    {
106
      retVal = true;
107
    }
108
 
109
    mLogger.info("compare returned " + retVal);
110
    return retVal;
111
  }
112
 
113
  /**runs exclude from build
114
   */
115
  void excludeFromBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
116
  {
117
    mLogger.debug("excludeFromBuild " + mId);
118
    Integer id = mId;
119
    Integer rootId = mRootId;
120
    Integer r = rtag_id;
121
    // a null version and log file is passed to oracle
122
    // the planned version is only needed to remove a planned version from the planned version table
123
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
900 mhunt 124
    // this is the one instance where an existing build failure must be superceded in the database
125
    rm.excludeFromBuild(id.toString(), null, r.toString(), rootId == -1 ? null : rootId.toString(), mRootCause, null, false, true);
866 mhunt 126
  }
127
 
128
  /**runs exclude from build
129
   */
130
  void includeToBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
131
  {
132
    mLogger.debug("includeToBuild " + mId);
133
    Integer id = mId;
134
    Integer r = rtag_id;
135
    // a null version and log file is passed to oracle
136
    // the planned version is only needed to remove a planned version from the planned version table
137
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
138
    rm.includeToBuild(id.toString(), r.toString());
139
  }
140
 
141
  /**
142
   * return true if the root_pv_id is null (-1) or the it points to a pv_id in the collection
143
   */
144
  boolean isRelevant(Vector<BuildExclusion> buildExclusionCollection)
145
  {
146
    mLogger.debug("isRelevant " + mId);
147
    boolean retVal = false;
148
 
149
    if ( mRootId == -1 )
150
    {
151
      retVal = true;
152
    }
153
    else
154
    {
155
      for (Iterator<BuildExclusion> it = buildExclusionCollection.iterator(); it.hasNext(); )
156
      {
157
        BuildExclusion buildExclusion = it.next();
158
 
159
        if ( buildExclusion.isRelevant( mRootId ) )
160
        {
161
          retVal = true;
162
          break;
163
        }
164
      }
165
    }
166
 
167
    mLogger.info("isRelevant " + mId + " returned " + retVal);
168
    return retVal;
169
  }
170
 
171
  /**
900 mhunt 172
   * return true if the root_pv_id is null (-1)
173
   */
174
  boolean isARootCause()
175
  {
176
    mLogger.debug("isARootCause " + mId);
177
    boolean retVal = false;
178
 
179
    if ( mRootId == -1 )
180
    {
181
      retVal = true;
182
    }
183
 
184
    mLogger.info("isARootCause " + mId + " returned " + retVal);
185
    return retVal;
186
  }
187
 
188
  /**
866 mhunt 189
   * return true if id matches mId
190
   */
191
    private boolean isRelevant(int id)
192
    {
193
      mLogger.debug("isRelevant " + mId + ", " + id);
194
      boolean retVal = false;
195
 
196
      if ( mId == id )
197
      {
198
        retVal = true;
199
      }
200
 
201
      mLogger.info("isRelevant " + mId +  ", " + id + " returned " + retVal);
202
      return retVal;
203
    }
204
 
205
  /**
206
    * user friendly
207
    * does not trigger a storm of emails because a low level package has a build issue
208
    * limit the emails to the low level package
209
    * i.e. only send email if the build exclusion has a null root pv id
210
    * and a non null root cause
211
   */
212
    public void email(Vector<Package>packageCollection, String mailServer, String mailSender, String release)
213
    {
214
      mLogger.debug("email " + mId);
215
      if ( mRootId == -1 && mRootCause != null )
216
      {
217
        // this is a direct build failure with a ripple engine induced root cause
218
        // send email
219
        Package pkg = null;
220
 
221
        for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
222
        {
223
          Package p = it.next();
224
 
225
          if ( compare(p.mId) )
226
          {
227
            pkg = p;
228
            break;
229
          }
230
        }
231
 
232
        if ( pkg != null )
233
        {
234
          // has the pkg any owners
235
          String owners = pkg.emailInfoNonAntTask();
236
 
237
          if ( owners != null )
238
          {
239
            String body =
240
            "Release: " + release + "<p>" +
241
            "Package: " + pkg.mName + "<p>" + 
242
            mRootCause;
243
 
244
            try
245
            {
246
              Smtpsend.send(
247
              mailServer, // mailServer
248
              mailSender, // source
249
              owners, // target
250
              null, // cc
251
              null, // bcc
252
              "BUILD FAILURE on package " + pkg.mName, // subject
253
              body, // body
254
              null // attachment
255
              );
256
            }
257
            catch( Exception e )
258
            {
259
            }
260
          }
261
        }
262
      }
868 mhunt 263
    }
264
 
265
    /**
266
     * hides how a root_pv_id is treated
267
     * only use root_pv_id if not equal to the pv_id
268
     * this is to drive a direct build exclusion in the release manager
269
    */
270
    private int dealWithNullRootPvId( int pvId, int rootPvId )
271
    {
272
      int retVal = rootPvId;
866 mhunt 273
 
868 mhunt 274
      if ( pvId == rootPvId )
275
      {
276
        // force a null root_pv_id in the database
277
        retVal = -1;
278
      }
279
 
280
      return retVal;
866 mhunt 281
    }
282
}